PDA

View Full Version : javascript CSS issue



The Titan
March 7th, 2008, 08:36 AM
This entire issue is probably really stupid and just needs another set of eyes (any programmer knows).... so here



<html>
<head><title>somthing</title></head>
<body>
<script type="text/javascript">
document.getElementById('inventory_head').style.ba ckgroundImage = "url('images/items/helm1.gif')";
</script>
<!-- A bunch of divs -->

<div id="inventory_head">
&nbsp;
</div>

<!--end all of those divs -->
</body>

</html>


the code is really long, generated by PHP so i didn't want to put it all here, but i think the issue may be because if all the divs.... but i suck at javascript so i don't know what you need to know... just post if you need more information

mike_g
March 7th, 2008, 10:45 AM
I think this should work:

<html>
<head><title>somthing</title></head>
<body>
<script type="text/javascript">
document.getElementById('inventory_head').style.ba ckground = "images/items/helm1.gif";
</script>
<!-- A bunch of divs -->

<div id="inventory_head">
&nbsp;
</div>

<!--end all of those divs -->
</body>

</html>

Edit: if it dosent work you might need to set the background after you declare the div. In which case it might be nice to wrap it in a function.

LaRoza
March 7th, 2008, 01:51 PM
Edit: if it dosent work you might need to set the background after you declare the div. In which case it might be nice to wrap it in a function.

Yes, the script comes before the elements are in the document tree.

Ideally, one would use an external file.



window.onload = function()
{
//All other code here.
}

The Titan
March 7th, 2008, 01:57 PM
thank you, that worked