Results 1 to 3 of 3

Thread: Unable to change background image of a layer

  1. #1
    Join Date
    Sep 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Unable to change background image of a layer

    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:

    Code:
    <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

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,625
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    1. change the following code

    Posted by: shivboy
    Code:
    document.getElementById('bannerDiv').style.backgroundImage = 'url("abc.jpg")';
    to the following one

    Code:
    document.getElementById('banner').style.backgroundImage = "url('abc.jpg')";
    2.
    Posted by: shivboy
    HTML Code:
    <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:
    HTML Code:
    <div id="banner" class="bannerDiv">This is a testing</div>

  3. #3
    Join Date
    Oct 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    or change the bannerDiv style name to something else like bannerStyle

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •