Is it possible to use multiple variables instead of selectors in jQuery

前端 未结 9 2491
半阙折子戏
半阙折子戏 2020-12-07 20:03

I know that it\'s faster to do the following:

var $header = $(\"#header\");
$header.css({color:\"#ff0000\"});
$header.find(\"a\").addClass(\"foo\");
<         


        
9条回答
  •  无人及你
    2020-12-07 20:43

    You could always set all of the elements to one variable:

    var $lis = $('#header li, #footer li');
    $($lis).css({color:"#ff0000"});
    

提交回复
热议问题