jQuery exclude elements with certain class in selector

前端 未结 3 423
情话喂你
情话喂你 2020-11-29 00:02

I want to setup a click event trigger in jQuery for certain anchor tags.

I want to open certain links in a new tab while ignoring ones with a certain class (before y

3条回答
  •  北海茫月
    2020-11-29 00:50

    You can use the .not() method:

    $(".content_box a").not(".button")
    

    Alternatively, you can also use the :not() selector:

    $(".content_box a:not('.button')")
    

    There is little difference between the two approaches, except .not() is more readable (especially when chained) and :not() is very marginally faster. See this Stack Overflow answer for more info on the differences.

提交回复
热议问题