mona Posted April 17, 2006 Share Posted April 17, 2006 hi, I have a problem to use the css style inside the java script:I am using style inside my code as follows:<html><head><title>LTU Computer Science Forum</title><style type="text/css">TABLE,TR,TD{ background: transparent; color: #ff00cc; background-color: #000000;}TABLE{ width: 100%; }</style><script language="JavaScript">function loading(){document.write('<img src="LTULogo.jpg" width="974" height="72"/>');var xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.load("forums.xml"); var doc=xmlDoc.documentElement; for(var i=0; i<doc.childNodes.length; i++) display(doc.childNodes(i));}function display(cat){document.write('<TABLE cellspacing="1" ><TR><TH COLSPAN="3">'+cat.getAttribute("NAME")+'</TH></TR>');document.write('<TR><TD>Forum</TD><TD>Topics</TD><TD>Replies</TD></TR>');for(var j=0;j<cat.childNodes.length;j++){var node=cat.childNodes(j);document.write('<TR><TD>'+node.childNodes(0).firstChild.text+'<br>'+node.childNodes(1).firstChild.text+'</TD><TD>'+node.childNodes(2).firstChild.text+'</TD><TD>'+node.childNodes(3).firstChild.text+'</TD></TR>');}document.write('</TABLE>');}</script></head><body onload="loading()"></body></html>since I'm using xml Dom so I'm obliged to put the table inside the javascript,this thing makes the style not working for the tableDoes any body know why and how to make it working? Link to comment Share on other sites More sharing options...
aspnetguy Posted April 17, 2006 Share Posted April 17, 2006 My guess is because you are using document.writeif you create the elements throught he DOM then append them to the page it should work. var tbl = document.createElement('table') I believe I read somewhere that W3C is going to depreciate document.write in favor of a DOM method...don't quote me on that though. Link to comment Share on other sites More sharing options...
Chocolate570 Posted April 17, 2006 Share Posted April 17, 2006 My guess is because you are using document.writeif you create the elements throught he DOM then append them to the page it should work.var tbl = document.createElement('table') I believe I read somewhere that W3C is going to depreciate document.write in favor of a DOM method...don't quote me on that though. <{POST_SNAPBACK}> Hah! I quoted you! :)But remember, document.createElement('table') will not work in IE or Opera. There's a different way of doing it...it's something like document.createElement('<table attribute="value"></table>'). But don't quote me on that Link to comment Share on other sites More sharing options...
aspnetguy Posted April 18, 2006 Share Posted April 18, 2006 Hah! I quoted you! :)But remember, document.createElement('table') will not work in IE or Opera. There's a different way of doing it...it's something like document.createElement('<table attribute="value"></table>'). But don't quote me on that <{POST_SNAPBACK}> Too late :)I wish IE would just work like every other browser...So many things that they supposedly support are buggy or don't work at all. Link to comment Share on other sites More sharing options...
raimo Posted April 18, 2006 Share Posted April 18, 2006 But remember, document.createElement('table') will not work in IE or Opera. There's a different way of doing it...it's something like document.createElement('<table attribute="value"></table>'). But don't quote me on that <{POST_SNAPBACK}> Sorry, but it will work with Opera! Tested with Opera 8.51, 8.52, 8.53 8.54 in Windows and newest Opera 9 TP2 (236) in Linux. This one will work with all those just fine:<script type="text/javascript"><!--var table = document.createElement('table'); table.setAttribute('width', 500); table.setAttribute('id', 'table1'); table.style.border = 'solid 2px #808080'; tr = document.createElement('tr'); for (var i = 0; i < 3; i++){ td = document.createElement('td'); td.style.backgroundColor = '#FF8080'; text = document.createTextNode('cell ' + i); td.appendChild(text); tr.appendChild(td); }table.appendChild(tr);document.getElementsByTagName("body")[0].appendChild(table);//--></script> but it will not work with MSIE. Link to comment Share on other sites More sharing options...
Chocolate570 Posted April 19, 2006 Share Posted April 19, 2006 Ok, ok. I was 50% right. Thanks for teaching my something :)And if anyone quotes me this time....i'm going to suspend them. The fact I was wrong should not be circulating around on this forum....or else... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now