Neemajn31
Neemajn31

Reputation: 17

Selector Not working

In jQuery, I made a complex selector but it's not working. Could someone tell me what I'm doing wrong?

$("#gig:nth-child('3'):contains(:not('a'))")

Thanks!

Upvotes: 1

Views: 139

Answers (3)

ktilcu
ktilcu

Reputation: 3128

nth-child accepts an integer not a string.

$("#gig:nth-child(3)")

Upvotes: 1

Alex Peattie
Alex Peattie

Reputation: 27637

:contains('a') matches elements containing the letter a in its text. If you're looking for elements without a child <a> link

$("#gig:nth-child(3):not(:has(a))")

Upvotes: 1

BoltClock
BoltClock

Reputation: 723448

If you're trying to select an element whose text doesn't contain the letter a, you'll want to switch the positions of :contains() and :not() as :contains() isn't supposed to contain another selector. Try this:

$("#gig:nth-child(3):not(:contains('a'))")

If you meant an a element rather than the letter a, use :has():

$("#gig:nth-child(3):not(:has(a))")

Upvotes: 2

Related Questions