“All but not” jQuery selector

后端 未结 7 1366
谎友^
谎友^ 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.

提交回复
热议问题