My HTML code goes like this:
<div id="single"><br><br>
1) effew<br>
<input name="answer0" id="answer0" value="1" type="radio"> ewf
<input name="answer0" id="answer0" value="2" type="radio"> avb
</div>
<div id="single"><br><br>
2) fe<br>
<input name="answer1" id="answer1" value="1" type="radio"> few
<input name="answer1" id="answer1" value="2" type="radio"> eww
<input name="answer1" id="answer1" value="3" type="radio"> tfs
</div>
I want to iterate the above div tags with id as single and then get the value of selected radio button within each div tag with id as single. The jQuery code written is:
$("input[name=single]").each( function() {
var val = $('input[name=answer]:checked').val();
alert(val);
});
The above jQuery code doesn’t seem to work. Pls. advice how can I fix it?
HTML
(notice that I changed
Idbyclasssince repeated ids are not allowedJS
jsFiddle demo