1

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?

RuntimeException
  • 1,135
  • 2
  • 11
  • 25

3 Answers3

7

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.

user229044
  • 232,980
  • 40
  • 330
  • 338
0

Try this

console.log($('#targeting input:radio:checked').val())

See jquery val

jvverde
  • 631
  • 3
  • 10
0

Try this:

console.log($(this).prop('checked'));

Will return true or false, depending on whether the radio button is checked.

Source

Community
  • 1
  • 1
cssyphus
  • 37,875
  • 18
  • 96
  • 111