views:

116

answers:

1

How can I select the 1st item in a wrapped set? I have $(":radio") This returns a wrapped set of two items. Is there any way I can select just the first item? Basically something like this but cleaner syntax

var singleListItem = $($(":radio")[0]);

That will probably work, but it looks hideous to me. Is there a better way to write this type of selector??

Thanks, ~ck in San Diego

+4  A: 

You could try:

var singleListItem = $(":radio:first");

See: http://docs.jquery.com/Selectors/first

Quintin Robinson
much much cleaner. Thanks. I was looking in the index of "jQuery in Action", and there is no entry for "first". It was written for 1.3.1 so maybe it wasn't in there yet. i.e. "Closest".
Hcabnettek
Good, glad it was what you were looking for.
Quintin Robinson
+1, I was mistaken $(":radio")[0] is the same as $(":radio").get(0). Don't know where I got the idea that they were different.
karim79