jQuery Passing $(this) to a Function

后端 未结 4 1581
轻奢々
轻奢々 2021-01-30 20:11

I have lines of code like this:

$(this).parent().parent().children().each(function(){
    // do something
});

It works well. But I need to run

4条回答
  •  清酒与你
    2021-01-30 20:54

    If you work in no-conflict mode (i.e. out of global scope), one of the possibilities is:

    jQuery.noConflict();
    
    (function ($) {
        $('#button').on('click', myFunction);
    }(jQuery));
    
    // or
    jQuery('#button').on('click', myFunction);
    
    function myFunction() {
        var that = jQuery(this);
        console.log(that);
    }
    

提交回复
热议问题