<input type="radio" name="group1" value="Milk"> Milk<br>
<input type="radio" name="group1" value="Butter"> Butter
$("????").change(function(){
alert($(this).val());
})
How is the best method for get current checked value from two input with one name? If i click on radio Milk then this should show me “Milk” etc.
I can add class for this and showing current value, but this is the best method?
Like this: Working demo http://jsfiddle.net/VtcPB/1/
Good read: http://api.jquery.com/attribute-equals-selector/
Also Like @Casper said for
groupuse :$('input[name ="group1"]')Demo http://jsfiddle.net/VtcPB/2/Or little more optimized http://jsfiddle.net/VtcPB/3/ using
this.valueinstead of$(this).val()Or Another with more accuracy demo: http://jsfiddle.net/VtcPB/4/
Hope this helps
code
OR
OR
OR