“All but not” jQuery selector

后端 未结 7 1357
谎友^
谎友^ 2020-12-05 16:44

I can select (using jQuery) all the divs in a HTML markup as follows:

$(\'div\')

But I want to exclude a particular div (say h

相关标签:
7条回答
  • 2020-12-05 17:42

    You use the .not property of the jQuery library:

    $('div').not('#myDiv').css('background-color', '#000000');
    

    See it in action here. The div #myDiv will be white.

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