Firing events on CSS class changes in jQuery

后端 未结 13 1199
天涯浪人
天涯浪人 2020-11-22 04:45

How can I fire an event if a CSS class is added or changed using jQuery? Does changing of a CSS class fire the jQuery change() event?

13条回答
  •  我寻月下人不归
    2020-11-22 05:06

    if you know a what event changed the class in the first place you may use a slight delay on the same event and the check the for the class. example

    //this is not the code you control
    $('input').on('blur', function(){
        $(this).addClass('error');
        $(this).before("
    Warning Error
    "); }); //this is your code $('input').on('blur', function(){ var el= $(this); setTimeout(function(){ if ($(el).hasClass('error')){ $(el).removeClass('error'); $(el).prev('.someClass').hide(); } },1000); });

    http://jsfiddle.net/GuDCp/3/

提交回复
热议问题