Babiker
Babiker

Reputation: 18798

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

I have an element that has children with different classes. How can I select all elements of certain class .cellDiv in the DOM, except those that are children of this?

Upvotes: 0

Views: 194

Answers (2)

adrian7
adrian7

Reputation: 1016

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 ... }

Upvotes: -1

Jacob Mattison
Jacob Mattison

Reputation: 51052

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')

Upvotes: 2

Related Questions