问题描述:

I need the content of $(this) in a function, I want to know the string inside this

;(function($) {

$.fn.extend({

myFunction : function () {

// if this contain "tr" i have to do some ...

}

});

$("#myTable tbody tr").myFunction();

})(jQuery);

网友答案:

You can access the selector inside your jQuery method via this.selector like so:

;(function($) {

   $.fn.extend({
        myFunction: function () {
            console.log(this.selector);
        }
    });
    $("#myTable tbody tr").myFunction();

})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
相关阅读:
Top