#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    54
    Rep Power
    12

    layer background image javascript


    I want to change the background image of a layer on a link's mouseover event. I got it to work in IE but need help with NS6. This is what I have...


    function showLayer(newcolor){
    if (document.all) {
    document.all.red.style.background='url('+newcolor+') no-repeat'
    }
    if (! document.all && document.getElementById) {
    // something here for NS6
    }

    }

    Thanks for your help!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2003
    Posts
    1,014
    Rep Power
    15
    This will do:
    Code:
    document.getElementById('red').style.background = 'url('+newcolor+') no-repeat'
    Or even simpler -and working in both IE and NS6-:
    Code:
    function showLayer(el,newcolor) {
    	el.style.background = 'url('+newcolor+') no-repeat'
    }
    <div id="mydiv" onmouseover="showLayer(this,'blue.gif')">red</div>
    Hope this helps,
    Jeroen
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    54
    Rep Power
    12
    beautiful, thanks!

IMN logo majestic logo threadwatch logo seochat tools logo