开发者

How can I select all elements of certain class except those that are children of this?

开发者 https://www.devze.com 2023-02-07 07:12 出处:网络
I have an element that has children with different cla开发者_JAVA百科sses.How can I select all elements of certain class .cellDiv in the DOM, except those that are children of this?How about

I have an element that has children with different cla开发者_JAVA百科sses. How can I select all elements of certain class .cellDiv in the DOM, except those that are children of this?


How about

$('.cellDiv').not($(this).find('.cellDiv'))

or, if you know that this has an id, it should be faster to do

$('.cellDiv:not(#' + this.id + ' > .cellDiv')


Well a good idea would be to do first an addClass to this like so $(this).addClass('selected'); then you'll know the this has also class 'selected' then you select all withhout 'selected' class for .... if(!$(element).hasClass('selected')){ ... select it ... }

0

精彩评论

暂无评论...
验证码 换一张
取 消