views:

507

answers:

4

Something is very awkward about my situation... i have something like this:

<div id="selector">
   <input type='radio' />
   <input type='radio' />
   <input type='radio' />
</div>

if I use $("#selector input[type=radio]") all three elements are found, but if I use $("#selector").find("input[type=radio]") or even find("input") only the first one is found.

Is this a bug in jQuery? Am I not using find() properly?

Clarification : I want to use find() to get all the inputs, but anything I try finds only the first one.

edit: i'm using jquery 1.3.2

A: 

Try

$("#selector").find("input[type=radio]")

Alexander Corotchi
that's what i'm using, sorry for the bad example :)
Dan
+2  A: 

What you really want is:

$("#selector > :radio")

As for why you're getting only one, I'd need to see the actual code that's being run because find() doesn't stop at one and will find all matches so it may be how you're using it afterwards that is the issue.

cletus
I was also trying this in the firebug console, and the two commands return different results: the compound selector returns all, the find() returns only the first one.
Dan
A: 

$("#selector").children("input[@type=radio]")

Alexander Corotchi
The @ to select attributes is no longer supported by jQuery
Philippe Leybaert
+1  A: 

The two code fragments should return the same result.

Are you saying that when you run the following code, the first alert will show "3" and the second "1" ?

var a = $("#selector input[type=radio]");
var b = $("#selector").find("input[type=radio]");

alert(a.length);
alert(b.length);

Can you please verify?

Philippe Leybaert
correct. that's why it's so bizzare.
Dan