Reputation: 18594
I want to get the value of the not checked radio button.
This is my code:
<input type="radio" name="myradios" value="rad1" checked="checked" />
<input type="radio" name="myradios" value="rad2" />
<script>
var notchecked = $('input:radio[name=myradios]:not(checked)');
console.log(notchecked.val())
</script>
But it gives me rad1
, instead of rad2
.
Here is a fiddle: https://jsfiddle.net/fsj1hm2g/
Upvotes: 2
Views: 101
Reputation: 49095
You need to correctly use the :checked
selector:
$('input:radio[name=myradios]:not(:checked)');
See Documetation
Upvotes: 3
Reputation: 15913
Use var notchecked = $('input:radio[name=myradios]:not(:checked)');
instead of :not(checked)
Upvotes: 0