If you have this form:
<form action="" method="post" id="myForm"> <input type="radio" name="myRadioButton" value="0" class="radio" id="firstRadioButton" /> Value </form>
You can select elements by their identifier:
selects a radio button
$("#firstRadioButton)
selects a form
$("#myForm")
Or select all the switches:
$("#myForm input.radio").each(function(){ alert($(this).val()); });
And without using identifiers:
HTML:
<form action="" method="post"> <input type="radio" value="1" /> Value 1 <br /> <input type="radio" value="2" /> Value 2 <br /> </form>
JQuery
alert($("form").first().find("input:radio").first().val());
Example: Look here
Sarah west
source share