Performance of jQuery selectors vs local variables

后端 未结 5 1403
清歌不尽
清歌不尽 2020-12-03 07:24

Is it recommended that, when I need to access the result of a jQuery selector more than once in the scope of a function, that I run the selector once and assign it to a loca

5条回答
  •  离开以前
    2020-12-03 07:59

    Don't forget this one:

    var execute = function(){ 
        $('.myElement')
            .css('color','green')
            .attr('title','My Element')
            .click(function(){ 
                console.log('clicked'); 
            });
    }
    

提交回复
热议问题