Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove one class value from a two part class setup

I have the following piece of code:

if((String(parent).length > 0) && (String(this.className).length > 0)) {

where this.className contains the value "top currentMenu"

Using this.className name, I need a means of removing from this.className, "currentMenu" ONLY using jQuery, so that the end result for this.className is just "top".

like image 341
tonyf Avatar asked Jan 23 '26 00:01

tonyf


1 Answers

It is simply:

$(this).removeClass('currentMenu')

Reference: .removeClass


In plain JavaScript you can do something like:

function removeClass(node, cls) {
    if(node && node.className && node.className.indexOf(cls) >= 0) {
        var pattern = new RegExp('\\s*' + cls + '\\s*');
        node.className = node.className.replace(pattern, ' ');
    }
}

Or I don't understand your problem :)

like image 136
Felix Kling Avatar answered Jan 24 '26 14:01

Felix Kling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!