javascript - Is there a bug with radio buttons in jQuery 1.9.1? -
i've been trying programatically select radio buttons jquery, thought simple changing checked attribute.
however, following code doesn't seem expected in jquery 1.9.1 in chrome/firefox.
expected behaviour: click div enclosing radio button -> 'checked' attribute gets set -> renders checked in dom.
actual behaviour: click div enclosing radio button -> 'checked' attribute gets set -> renders checked in dom first , second button clicked, subsequent buttons don't render checked.
jquery:
$('div.form-type-radio').on('click', function () { var id = $(this).find('input[type=radio]').attr('id'); $('form input[type=radio]:not(#'+id+')').removeattr('checked'); $('#' + id).attr('checked', 'checked'); console.log($('#' + id)); }); here's jsfiddle - http://jsfiddle.net/gl9gc/
i've tried same code previous versions of jquery , works expected.
in case, should use prop() instead of attr()/removeattr().
here's working jsfiddle.
jquery:
$('div.form-type-radio').on('click', function () { var id = $(this).find('input[type=radio]').prop('id'); $('form input[type=radio]:not(#'+id+')').prop('checked'); $('#' + id).prop('checked', 'checked'); console.log($('#' + id)); });
Comments
Post a Comment