phorcon3 Posted March 8, 2008 Share Posted March 8, 2008 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); Quote Link to comment https://forums.phpfreaks.com/topic/95053-createelement/ Share on other sites More sharing options...
haku Posted March 9, 2008 Share Posted March 9, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/95053-createelement/#findComment-487721 Share on other sites More sharing options...
nogray Posted March 11, 2008 Share Posted March 11, 2008 div1.className = "class1"; works in any grade A browser Quote Link to comment https://forums.phpfreaks.com/topic/95053-createelement/#findComment-489708 Share on other sites More sharing options...
haku Posted March 11, 2008 Share Posted March 11, 2008 But its not in line with correct DOM standards, and may lose the ability to be backwards compatible in future browser releases. Correct DOM standards use setAttribute("class", "classname"). Therefore its better to use this, and then use a fix for IE which doesn't meet standards. Quote Link to comment https://forums.phpfreaks.com/topic/95053-createelement/#findComment-490039 Share on other sites More sharing options...
phorcon3 Posted March 13, 2008 Author Share Posted March 13, 2008 uh, thanks a bunch haku!! Quote Link to comment https://forums.phpfreaks.com/topic/95053-createelement/#findComment-491655 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.