jQuery: Checking a Radio Button with attr() doesn't work? -
not sure if bug in jquery 1.4.2 - can't figure out why won't work.
i need check radio button. i'm using attr({'checked':'checked'})
, tried attr('checked':true)
- none work. if attr('title':'whatever')
on same radio button, no other change anyhwere, work everytime.
is there obscure difference between title
attribute , checked
attribute i'm missing? both everyday html attributes. why 1 work , other 1 doesn't?
here's code:
$('.formradiodiv').live('click', function() { //remove checked radio btns $('input', $(this).parents('#radiogroup')).each(function() { $(this).removeattr('checked'); }); $('input', $(this)).attr('checked', true); });
edit: alright, believe got it. apparently worked along, , head temporarily being in tukka tukka land or something.
i checking source code see if jquery had added "checked" attr radio button clicking on: in firefox, highlight content, right click > view selection source. doing shows changes dom done javascript, , expecting see attribute in source code.
all time, html radio button hidden via css. that's reason need in first place - i'm replacing default radio button image.
so in source code, didn't see checked
attribute on radio button, hence assumed jquery not working correctly. removed css rule, , showed buttons testing, saw checked correctly. nuff said.
thank commented. i'll vote y'all up. cheers
jab in dark: suspect $('input', $(this))
matches other types of <input>
elements besides check boxes, , goes wrong when setting checked
attribute of elements.
try restrict selector check boxes (also note don't need wrap this
when using selector context):
$("input:checkbox", this).attr("checked", "checked");
Comments
Post a Comment