0

In this code snippet from AdvancED DOM Scripting:

The call to delete(classes[i]); is this an array or object method? I'm unable to Google an answer.

/**
 * remove a class from an element 
 */
function removeClassName(element, className) {
    if(!(element = $(element))) return false;
    var classes = getClassNames(element);
    var length = classes.length
    //loop through the array in reverse, deleting matching items
    // You loop in reverse as you're deleting items from 
    // the array which will shorten it.
    for (var i = length-1; i >= 0; i--) {
        if (classes[i] === className) { delete(classes[i]); }
    }
    element.className = classes.join(' ');
    return (length == classes.length ? false : true);
};
window['ADS']['removeClassName'] = removeClassName;
1

3 Answers 3

2

The Mozilla Reference Docs says the following regarding the delete operator:

The delete operator deletes an object, an object's property, or an element at a specified index in an array.

For more information, see the following article:

http://perfectionkills.com/understanding-delete/

Sign up to request clarification or add additional context in comments.

3 Comments

@jondavidjohn LOL! It means that it can be used on objects, object properties, and array elements. Still not clear? perfectionkills.com/understanding-delete
yes, that's a top result in google, but "The delete operator deletes an object..." is a self reliant definition...
@Phil Klien.Thanks found the article mentioned, during your reply. Most serendipitous. To all, many thanks.
1

delete will set the value of the specified member (variable/array/object) to undefined

array/object example...

since classes[i] is actually referencing the i index of the array. It will set that specific index position to undefined, reserving the position in the array...

Comments

0

I think you can use simply $('p').removeClass('myClass yourClass') with jquery and put together a function to do so for any element

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.