By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,046 Members | 2,058 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

Browser Quirk: Dynamically appended checked checkbox does not appear checked (IE)

Expert Mod 15k+
P: 16,027
Dynamically appended checkbox element does not appear checked despite setting the checked property state to true or "checked".

Internet Explorer

The Javascript code:
Expand|Select|Wrap|Line Numbers
  1. var cb = document.createElement("input");
  2. cb.type = "checkbox";
  3. = "checkbox1";
  4. = "cbID";
  5. cb.checked = true;
  6. obj.appendChild(cb);
Use defaultChecked instead of checked:
Expand|Select|Wrap|Line Numbers
  1. cb.defaultChecked = true;
Alternative Solution
Set the checked state after appending the checkbox:
Expand|Select|Wrap|Line Numbers
  1. obj.appendChild(cb);
  2. cb.checked = true;
More Bugs, Quirks and Inconsistencies
Aug 18 '07 #1
Share this Article
Share on Google+