Event detect when css property changed using Jquery

后端 未结 5 1070
北海茫月
北海茫月 2020-11-22 12:30

Is there a way to detect if the \"display\" css property of an element is changed (to whether none or block or inline-block...)? if not, any plugin? Thanks

5条回答
  •  Happy的楠姐
    2020-11-22 12:52

    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 == "display") { // which attribute you want to watch for changes
                if(evnt.newValue.search(/inline/i) == -1) {
    
                    // your code to execute goes here...
                }
            }
        }
    });
    

提交回复
热议问题