Jump to content

createElement


phorcon3

Recommended Posts

can someone please tell me what im doin wrong? it seems to be workin fine in IE but not FF ...so ..obviously it must be crappy codin, since only IE accepts that sorta codin

 

var div0 = document.createElement('div');

var div1 = document.createElement('<div class="class1"></div>');

var div2 = document.createElement('div');

var text = document.createTextNode('test');

div2.appendChild(text);

var div3 = document.createElement('<div class="class3"></div>');

div0.appendChild(div1);

div0.appendChild(div2);

div0.appendChild(div3);

var body = document.getElementsByTagName('body')[0];

body.appendChild(div0);

Link to comment
https://forums.phpfreaks.com/topic/95053-createelement/
Share on other sites

There are some problems in your code, but the problem is that IE sucks and accepts your bad code. If IE was better designed in the first place, your code wouldn't have worked in the first place, and you would have realized then. So dont worry about it too much.

 

Anyways, you cannot create an element with classes the way you did. Here is how you do it in IE:

 

var div1 = document.createElement('div');
div1.className = "class1";

 

and here is how you do it in FF:

 

var div1 = document.createElement('div');
div1.setAttribute("class","class1")

 

What you have to do is create an if/else statement that identifies whether the user is using IE or FF, and then uses the proper code. I'll leave it to you to hit google and figure out how to do that - its the easy part!

Link to comment
https://forums.phpfreaks.com/topic/95053-createelement/#findComment-487721
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.