JQuery Detect class changes

前端 未结 3 625
北荒
北荒 2020-12-05 10:41

I am using a plugin that added a class open to .slide-out-div when opened.

So I am trying to change some css if the open is detected.

3条回答
  •  醉酒成梦
    2020-12-05 11:41

    You can use attrchange jQuery plugin. The main function of the plugin is to bind a listener function on attribute change of HTML elements.

    Code sample:

    $("#myDiv").attrchange({
        trackValues: true, // set to true so that the event object is updated with old & new values
        callback: function(evnt) {
            if(evnt.attributeName == "class") { // which attribute you want to watch for changes
                if(evnt.newValue.search(/open/i) == -1) { // "open" is the class name you search for inside "class" attribute
    
                    // your code to execute goes here...
                }
            }
        }
    });
    

提交回复
热议问题