By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,030 Members | 1,997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,030 IT Pros & Developers. It's quick & easy.

createElement not working in IE

P: 13
Hi,

I wrote a javascript code as follows

Expand|Select|Wrap|Line Numbers
  1. function fun1()
  2. {
  3.                 var element = document.createElement('input');
  4.         element.type='checkbox';
  5.         element.checked='checked';
  6.                 body.appendChild(element);
  7.  
  8.  
  9. }
this code is working fine in Firefox but in IE the checkbox is creating but it is unchecked.
I want a checked check box(It is coming in firefox)

Help me out please
Oct 10 '08 #1
Share this Question
Share on Google+
3 Replies


Dormilich
Expert Mod 5K+
P: 8,639
try:
element.checked = true;

regards
Oct 10 '08 #2

P: 13
thanks for response

I got it.It can be done just by writing
element.checked='checked';
after append
as follows the complete code:

Expand|Select|Wrap|Line Numbers
  1. function fun1()
  2. {
  3.  
  4. var element = document.createElement('input')
  5.         element.type='checkbox';
  6.         body.appendChild(element);
  7.         element.checked='checked';
  8. }
Oct 10 '08 #3

acoder
Expert Mod 15k+
P: 16,027
That's correct, or you can use the defaultChecked property. See Dynamically appended checked checkbox does not appear checked.
Oct 10 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.