Reputation: 1135
Using this jquery code:
$("#targeting input:radio").each(function() {
console.log ($(this).attr("selected"));
});
HTML:
<input type="radio" id="dateFromTo" name="muScheduleDateRange" value="2" selected="someval"/>
In console.log I'm getting selected
instead someval
?
Upvotes: 1
Views: 92
Reputation: 239301
selected
is a boolean. You can't set it to anything except undefined
or "selected"
. If you want to attach some value to the input
, use the value
attribute. If you want to attach some additional value to the input
, use a data attribute.
Upvotes: 7
Reputation: 40038
Try this:
console.log($(this).prop('checked'));
Will return true or false, depending on whether the radio button is checked.
Upvotes: 0
Reputation: 631
Try this
console.log($('#targeting input:radio:checked').val())
See jquery val
Upvotes: 0