Reputation: 345
i am using: http://blogs.digitss.com/javascript/jquery-javascript/jquery-fancy-custom-radio-and-checkbox/
simple code:
<input type="radio" id="a1" class="b1" name="shipping" checked value="single">
<input type="radio" id="a1" class="b1" name="shipping" value="married">
<input type="radio" id="a1" class="b1" name="shipping" value="widowed">
simple head:
$(document).ready(function(){
$(".radio").dgStyle();
$(".checkbox").dgStyle();
});
if i add to $(document).ready , after ($".checkbox").dgStyle(); The following:
alert($('input:radio[name=shipping]:checked').val());
it works fine!
but - if i do something like that, it is not working:
$(function() {
$("input:radio[name=shipping]:checked").change(function() {
alert("123");
});
});
i tried to remove :checked, still not working.
Upvotes: 2
Views: 11696
Reputation: 73906
Ok, I got this:
$(".radio").click(function() {
alert('ID : ' + $(this).find('input:radio').prop('id'));
alert('Value : ' + $(this).find('input:radio').prop('value'));
});
Upvotes: 6
Reputation: 19327
You must remove the :checked
on the selector
$(function() {
$("input:radio[name=shipping]").change(function() {
alert('123');
});
});
NOTE: please make sure you don't use same ID's on your elements its really a bad practice or else you will face a lot of issues
Upvotes: 3