Is it possible to check if a class is removed in jquery

烂漫一生 提交于 2019-12-25 08:35:56

问题


I would like to know if a class is removed. something like:

if(".class" is removed) then { get class.object}

I need to know it, because I need the object in wich the class is being removed.

Thanks,

Mark


回答1:


Use hasClass:

if($("selector").hasClass(".class")) {...}



回答2:


If you can be sure that the removal happens via jQuery, hook the method.

var _oldremove = jQuery.fn.removeClass;
jQuery.fn.removeClass = function() {
    if( arguments[0] === 'the_class_you_are_looking_for' ) {
        // do something with this === current object
    }

    _oldremove.apply(this, arguments);
};

Be aware that you might need to overwrite more methods, like .toggleClass.




回答3:


Does .hasClass("someclass") suit your needs? How will it be removed? Or du you want a trigger for when removing the class?



来源:https://stackoverflow.com/questions/4657972/is-it-possible-to-check-if-a-class-is-removed-in-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!