Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 956
luqita Avatar asked Oct 24 '11 19:10

luqita


2 Answers

Try this instead:

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

http://jsfiddle.net/sFtdR/

like image 145
jbabey Avatar answered Nov 04 '22 04:11

jbabey


Try this

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

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

like image 35
Vikas Naranje Avatar answered Nov 04 '22 04:11

Vikas Naranje