Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery core method overload

Tags:

jquery

how can I overload or extend (or intercept) jQuery's .html() method so that it works its default way unless the object has a certain class?

Thanks

like image 710
pistacchio Avatar asked Aug 24 '26 19:08

pistacchio


1 Answers

You just overwrite the function while maintaining a reference to the original.

var jq_html_function = $.fn.html;

$.fn.html = function() {
    $(this).each(function() {
        if($(this).hasClass('someclass')) {
            // Do something
            return;
        }
        jq_html_function.apply(this, arguments);
    });
};
like image 89
BC. Avatar answered Aug 26 '26 09:08

BC.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!