views:

98

answers:

5

Hello there, I have a div with id kGrowl and inside that div I have another div that has a select element with name = mover. I try to use this selector:

$('#kGrowl:contains([name=mover])').length

But it is currently returning 0. How is my selector wrong?

Thanks.

Edit:

Gabriel's answer is best but I also realized its the :has attribute that will take a jQuery selector, not contains. So you could do:

$('#kGrowl:has([name=mover])').length
A: 

Try this:

$('#kGrowl[name=mover]');

Edit: for elements with name=mover inside kGrowl:

$('#kGrowl div[name=mover]'); //note the space

Also check this page for more information on selectors http://api.jquery.com/category/selectors/

Ropstah
+1  A: 

I'm unfamiliar with :contains, but perhaps you should try:

$('#kGrowl *[name=mover]').length
Matthew Scharley
A: 

try this:

$("#kGrowl:contains('[name=mover]')").length
GerManson
A: 

:contains isn't needed as it is implied by the query that the second element resides inside the first one.

Anders Mattson
+2  A: 

contains is mostly for text content where a valid selector doesn't work. So if you wanted to do it the way you are showing it would be:

$('#kGrowl:contains("name=mover")').length but really you want the number of select elements named mover you would use:

$("#kGrowl div select[name='mover']").length

cheers.

Gabriel
Also I just realized its `:has` that takes an actual jQuery selector. Lol.
Alex
@Alex word... I was trying to remember which one it was also.
Gabriel