Jump to content


Photo

CSS inside JAVASCRIPT


  • Please log in to reply
1 reply to this topic

#1 manamino

manamino
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 April 2006 - 02:45 AM

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 table
Does any body know why and how to make it working?

#2 Volte

Volte
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 27 April 2006 - 12:07 PM

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";

UNIX ALL THE WAY BABY!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users