PDA

View Full Version : Unable to change background image of a layer



shivboy
09-29-2006, 06:28 AM
Hi,

I've been trying to change the background image of a layer using JS, but in vain. The code that I am using is as follows:



<style>
.bannerDiv {top: 5px; left: 2px; position: absolute;}
</style>

function init()
{
document.getElementById('bannerDiv').style.backgroundImage = 'url("abc.jpg")';
}

<body onload="init()">

<div id="bannerDiv" class="bannerDiv"></div>

</body>


There is no error generated, but the image does not show in the layer also. Where am I going wrong? Please help.

Peace,

Shivboy

codeexploiter
10-10-2006, 06:43 AM
1. change the following code



Posted by: shivboy

document.getElementById('bannerDiv').style.backgroundImage = 'url("abc.jpg")';

to the following one



document.getElementById('banner').style.backgroundImage = "url('abc.jpg')";


2.
Posted by: shivboy

<div id="bannerDiv" class="bannerDiv"></div>


Change the id into something other than bannerDiv for example banner will do and specify some text between the <div> and </div> tag inorder to view the background image.

For Eg:

<div id="banner" class="bannerDiv">This is a testing</div>

nelis
10-10-2006, 04:31 PM
or change the bannerDiv style name to something else like bannerStyle