Is it possible to select $(this) AND use selectors in jQuery

前端 未结 1 1857
小鲜肉
小鲜肉 2021-02-20 00:27

I\'m wondering if I can use $(this) as well as a class selector before running a function on them.

So rather than doing;

$(this).toggleClass(\'open\');
$         


        
相关标签:
1条回答
  • 2021-02-20 01:00

    You can use add():

    $(".closed").add(this).toggleClass("open");
    

    It will add this element to the set of matched elements (i.e. .closed).

    0 讨论(0)
提交回复
热议问题