luqita
luqita

Reputation: 4077

jQuery: How to select all radio buttons with a name?

I am trying to select all radio buttons with a name, but I can only select the checked ones. For example this works:

$("input[@name='id']:checked").each(function() { // });

It selects all inputs with name id, which are checked (in this case one radio button). But I need all of them, as I need the not checked ones for this name, on this function.

This, for example, is not doing anything:

$("input[@name='id']").each(function()  { // });

What do I do?

Thanks!

Upvotes: 7

Views: 16497

Answers (3)

Vikas Naranje
Vikas Naranje

Reputation: 2392

Try this

$(':input[type="radio"]').each(function(index){
     // YOUR CODE
});

above code will select all input element who's type attribute is radio.

Upvotes: 3

Jayendra
Jayendra

Reputation: 52769

Try -

$("input[name='id']").each(function()  { 
    alert($(this).attr('name'));
});

Upvotes: 1

jbabey
jbabey

Reputation: 46647

Try this instead:

$('input[name="yourName"]').each(function () { ... });

http://jsfiddle.net/sFtdR/

Upvotes: 13

Related Questions