Ian Vink
Ian Vink

Reputation: 68790

jQuery selector on a collection

In my code I have the following which gets a collection of the Country radio controls:

model.countries = $('input:radio[name="Country)"]');

Later in the code I need to know the val() of the "checked" radio. How do I get to it?

I've tried:

model.countries.is(':checked')

but that of course just finds if any is checked. I need the val() of the checked radio.

Upvotes: 0

Views: 49

Answers (1)

Stryner
Stryner

Reputation: 7328

You can use .filter(selector) to filter your current selection, then call .val() to retrieve the value of the desired element:

model.countries.filter(':checked').val()

Upvotes: 6

Related Questions