manamino Posted April 17, 2006 Share Posted April 17, 2006 hi, I have a problem to use the css style inside the javascript:I am using style inside my code as follows:[!--coloro:#339999--][span style=\"color:#339999\"][!--/coloro--]<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>[!--colorc--][/span][!--/colorc--]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? Quote Link to comment https://forums.phpfreaks.com/topic/7572-css-inside-javascript/ Share on other sites More sharing options...
Volte Posted April 27, 2006 Share Posted April 27, 2006 when you use document.write, it clears whatever is on the screen, and writes that on the page. basically you lose you CSS, and everything else that you don't rewrite. Try putting an element on your page such as <div id="content"></div>, and then doing:document.getElementById("content").innerHTML = "<Table> your table stuff here or whatever"; Quote Link to comment https://forums.phpfreaks.com/topic/7572-css-inside-javascript/#findComment-31286 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.