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

2019-08-27 14:13发布

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

标签: jquery class
3条回答
Emotional °昔
2楼-- · 2019-08-27 14:40

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楼-- · 2019-08-27 14:44

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

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-08-27 14:48

Use hasClass:

if($("selector").hasClass(".class")) {...}
查看更多
登录 后发表回答