Reputation: 6399
I am trying to implement a simple check all option. On click of a check box, all the checkboxes in the page should get selected. First attempt is to check the value of the master check box
The below code works fine in Firefox, but not in IE8. How to get around the problem
function checkAll()
{
alert("value of checkbox = "+ $('#mastercheckbox').attr('checked') )
}
and the html code
<input type="checkbox" id="mastercheckbox" onchange="checkAll();"/>
Upvotes: 2
Views: 3473
Reputation: 11552
Look into prop()
: http://api.jquery.com/prop/
The docs provide multiple of better ways to check for a "checked" checkbox.
elem.checked | true (Boolean) Will change with checkbox state
$(elem).prop("checked") | true (Boolean) Will change with checkbox state
elem.getAttribute("checked") | "checked" (String) Initial state of the checkbox; does not change
$(elem).attr("checked")(1.6) | "checked" (String) Initial state of the checkbox; does not change
$(elem).attr("checked")(1.6.1+) | "checked" (String) Will change with checkbox state
$(elem).attr("checked")(pre-1.6) | true (Boolean) Changed with checkbox state
Upvotes: 1