jQuery .removeClass() not working

Had this problem earlier on. Am no expert in jquery yet so I don't know if it behaves like css' specificity. My fix was to remove the class by using higher specificity. e.g Instead of using $(this).removeClass('acb'), try using higher specificity like $('#div1').children().first()


I'm not sure if this will fit your specifications, but the jQuery attr() method will take two arguments and replace all of the classes with the class name your provide. This won't work if you have other classes that you want to keep on your element, but if not try:

    $("#stadtInput").attr("class", "textboxRight");

The next few lines works for me

var current = $(el).closest(".panel").find(".panel-collapse");
    if( $(current).hasClass("in") ) {
        setTimeout(function(){///workaround
            $(".panel-collapse").removeClass("in");
        }, 10);
    } else {
        $(current).addClass("in");
    }

I had the same issue when working on a rails app with the HAML templating gem as I included the # at the very beginning and it is not really needed. When I removed it, it started working.

Hope this helps! :)

Tags:

Css

Jquery