I have a function that’s called by a link which should check various checkboxes which exist inside a specific div (passed to the function.) Works in all browsers except IE (7.) As far as I can tell .attr(‘checked’, ‘checked’ is the proper way to do this using jquery 1.5.1
function selectall(industry){
$("#"+industry+"Apps :checkbox").attr('checked', 'checked');
$("#"+industry+"Apps :checkbox").change(); /* used for jqtransform plugin */
}
Is there something I’m missing or a better way to do this that works in all browsers? I don’t really care about un-selecting, just selecting.
HTML looks like
<div id = 'HealthcareApps'>
<div style="clear: both;">
<a href = "javascript:selectall('Healthcare');">Select all</a>
</div>
<ul>
<li><label for="id_Healthcare_0"><input type="checkbox" name="Healthcare" value="1" id="id_Healthcare_0" /> Simple Messaging</label></li>
<li><label for="id_Healthcare_1"><input type="checkbox" name="Healthcare" value="2" id="id_Healthcare_1" /> Mobile Alerts and Alarms</label></li>
<li><label for="id_Healthcare_2"><input type="checkbox" name="Healthcare" value="3" id="id_Healthcare_2" /> Patient Identification / Drug Conflicts</label></li>
</ul>
(yes, I know inline styles are a horrible idea. I’ll fix that as well if I can ever get this link to work in IE.)
You could try something like this: js fiddle demo
jquery:
And, to toggle on and off:
js fiddle toggle demo