PDA

View Full Version : Passing a variable in Javascript


csam0003
05-07-2009, 05:53 AM
Hi all,

I have a css file as below:


treechildren::-moz-tree-cell(makeItBlue00FF00)
{
background-color: blue;
}



I am using the following line to append the css style to a tree cell

prop.AppendElement(aserv.getAtom("makeItBlue00FF00"));


Everything works great, however I now wish to pass the color as a variable from javascript- this way I do not need to declare several styles in the CSS file. How can I do this? How do I modify the style sheet and how do I modify the Js to pass the variable.

Thanks

Kind regards

Chris

Kor
05-12-2009, 05:05 PM
prop.AppendElement(aserv.getAtom("makeItBlue00FF00"));

It is impossible to say, as it your code is not written in plain javascript. If you use a framework (JQuery, Prototype, Mootools... whichever), then you should know it is very difficult to modify their codes, as those codes are obfuscated, intricate and very difficult to follow or debug.

itsallkizza
05-12-2009, 05:22 PM
If you're wanting to change a specific style (eg background-color) then you don't even need to mess with CSS, just change it in JS:

function changeStyle(of,style,to)
{
of.style[style] = to;
}

window.onload = function()
{
changeStyle(document.getElementsByTagName("body")[0],"backgroundColor","#000000");
}