views:

73

answers:

3

HTML

<input type="radio" name="rdName" id="uniqueID1" value="1" checked="checked">
<input type="radio" name="rdName" id="uniqueID2" value="2">
<input type="radio" name="rdName" id="uniqueID3" value="3">

jQuery #1

$('input:radio[name=rdName]:checked').val();

jQuery #2

$('input[name=rdName]:checked');

jQuery #1 gets the value of checked radio, but I need to get the whole object to get the ID. jQuery #2 get this (from Chrome Dev console). Object "0" is the actual object I need, but I am unable to just that.

0: HTMLInputElement
constructor: function Object()
context: HTMLDocument
length: 1
prevObject: Object
selector: input[name=rdName]:checked
__proto__: Object

Any ideas how to isolate the needed object ?

+1  A: 

You can access the elements in the jQuery object as an array:

var element = $('input[name=rdName]:checked')[0];

Or you can use the get method:

var element = $('input[name=rdName]:checked').get(0);
Guffa
Thanks. Did not even think of accessing it as an array.
Kim
+1  A: 
$('input:radio[name=rdName]:checked').attr('id');
bruno
+1  A: 

You mean this:

  alert($('input[name=rdName]:checked').get(0));
Sarfraz