Dynamically get radio button group name using jQuery
Something like the following should work:
$('input').click(function() {
var thisName = $(this).attr('name');
var qNum = thisName.substring(1);
var ans2 = $('input[name=' + thisName + ']:radio:checked').val();
getUserAnswer(thisName, ans2);
});
$('input:radio').click(function() {
console.log($(this).attr('name'));
});
You are selecting new set of elements on click, but you need the attr of the current element so, you need to refer to it with 'this'