Reputation: 1855
I have the following code although is there a more elegant way to getting the selected radio value as I'm already inside the code for the radio button group. This is to get the selected radio button within a group. Many thanks,
$('input[name=pig]').change(function () {
// this seems redundant
namespace('bla').myVariable = $('input[name=pig]:checked').val();
// ie. something like
namespace('bla').myVariable = $(this).checked.val();
});
Upvotes: 0
Views: 61
Reputation: 160833
$(this).val()
is just enough:
$('input[name=pig]').change(function () {
console.log($(this).val()); // or this.value
});
Upvotes: 0
Reputation: 20250
I think this is what you're trying to achieve:
namespace('bla').myVariable = this.value;
Upvotes: 1