Evgenij Reznik
Evgenij Reznik

Reputation: 18594

Getting name of not checked radio button

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

Answers (2)

haim770
haim770

Reputation: 49095

You need to correctly use the :checked selector:

$('input:radio[name=myradios]:not(:checked)');

See Documetation

Upvotes: 3

Tushar Gupta
Tushar Gupta

Reputation: 15913

Use var notchecked = $('input:radio[name=myradios]:not(:checked)'); instead of :not(checked)

Upvotes: 0

Related Questions