简体   繁体   中英

jQuery: how to override default methods (i.e html, append) for particular element?

So for example I what that after automaticaly execute come code after I call el.html("...") how do I override the cored method for specific element?

I found that http://www.bennadel.com/blog/1624-Ask-Ben-Overriding-Core-jQuery-Methods.htm but I can not get how override core method only for a particular element.

Why not just filter the current object and loop through the items you want? Something like this should work:

(function(){
    var original = jQuery.fn.append;

    jQuery.fn.append = function(){
        this.filter("yourselector").each(function(){
            // Do stuff
        });

        return original.apply(this, arguments);
    }
})();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM