Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude when parent has class

Tags:

jquery

trying to exclude a set of elements from the matched set when it's parent object has a cetain class.

current solution is:

$("#pages li a").not($(this).parent().hasClass('no-script'))

but this is not behaving as I would expect, what am I doing wrong?

like image 983
Mild Fuzz Avatar asked Nov 04 '10 11:11

Mild Fuzz


1 Answers

You want to use a :not() selector on the parent, like this:

$("#pages li:not(.no-script) a")

If there many be multiple levels, make sure it's the current level's parent by using a child selector (>):

$("#pages li:not(.no-script) > a")
like image 64
Nick Craver Avatar answered Oct 18 '22 01:10

Nick Craver