JQuery - find a radio button by value
Try this:
$(":radio[value=foobar]")
This will select all radio buttons with the attribute value="foobar"
.
I'm using jQuery 1.6 and this did not work for me: $(":radio[value=foobar]").attr('checked',true);
Instead, I'm using: $('[value="foobar"]').attr('checked',true);
and it works great.
The actual code I'm using clears the radios first and uses prop
instead of attr
$('[name=menuRadio]').prop('checked',false);$('[name=menuRadio][value="Bar Menu"]').prop('checked',true);
This can be achieved by this too:
$('input[type="radio"][value="aaa"]').val();
This will select the radio which has the value of aaa
With .filter()
method:
var radio = $('input[type="radio"]').filter(function(){ return this.value === 'aaa'; }).val();