Jump to content

[SOLVED] Div Rollover Not Working


treeleaf20

Recommended Posts

All,

I'm trying to resize some images when the page loads and this works fine. However when I try and rollover them it doesn't show anything. Here is the code:

<html>
<script>
function resizeAll( )
{
    var divs = document.getElementsByTagName("div");
    for ( var d = 0; d < divs.length; ++d )
    {
        var div = divs[d];
        if ( div.className == "fn-area" )
        {
    divid = divs[d].getAttribute("id");
    imgid = "Img" + divid;
    var Div1Width, Div1Height;
    	    Div1Width = document.getElementById(divid).offsetWidth;
            Div1Height = document.getElementById(divid).offsetHeight;
            document.getElementById(imgid).style.width = Div1Width;
            document.getElementById(imgid).style.height = Div1Height;
        }
    }
}
</script>
<head>

</head>
<body onLoad="resizeAll()">
<div id="Div1" class="fn-area" style="width:100px;height:100px; border:1px solid black;" onmouseover="this.getElementsById('ImgDiv1').style.display='block';" onmouseuut="this.getElementsById('ImgDiv1').style.display='none';">
<img id="ImgDiv1" src="fnclientlib/styles/artwork/stamp5.gif" style="display:none"/>
</div>

<div id="Div2" class="fn-area" style="width:300px;height:300px; border:1px solid black;" onmouseover="this.getElementsById('ImgDiv2').style.display='block';" onmouseout="this.getElementsById('ImgDiv2').style.display='none';">
<img id="ImgDiv2" src="fnclientlib/styles/artwork/stamp5.gif" style="display:none"/>
</div>
</body
</html>

How can I get the images to show when I rollover them? Thanks in advance.

Link to comment
Share on other sites

<html>
<script>
function resizeAll( )
{
    var divs = document.getElementsByTagName("div");
    for ( var d = 0; d < divs.length; ++d )
    {
        var div = divs[d];
        if ( div.className == "fn-area" )
        {
		divid = divs[d].getAttribute("id");
		imgid = "Img" + divid;
		var Div1Width, Div1Height;
    		Div1Width = document.getElementById(divid).offsetWidth;
            Div1Height = document.getElementById(divid).offsetHeight;
            document.getElementById(imgid).style.width = Div1Width;
            document.getElementById(imgid).style.height = Div1Height;
        }
    }
}
</script>
<head>

</head>
<body onLoad="resizeAll()">
<div id="Div1" class="fn-area" style="width:100px;height:100px; border:1px solid black;" onmouseover="this.getElementById('ImgDiv1').style.display='block';" onmouseout="this.getElementById('ImgDiv1').style.display='none';">
<img id="ImgDiv1" src="fnclientlib/styles/artwork/creep_stamp5.gif" style="display:none"/>
</div>

<div id="Div2" class="fn-area" style="width:300px;height:300px; border:1px solid black;" onmouseover="this.getElementById('ImgDiv2').style.display='block';" onmouseout="this.getElementById('ImgDiv2').style.display='none';">
<img id="ImgDiv2" src="fnclientlib/styles/artwork/creep_stamp5.gif" style="display:none"/>
</div>
</body
</html>

Link to comment
Share on other sites

well, my guess is that you're using incorrect syntax to refer to the element of interest. this line:

 

this.getElementById('ImgDiv1').style.display='block';

 

is probably spitting back an unknown method error. that's because technically, the div object you're referring to with "this" doesn't have that method. it's a method of the document object. if you want to use "this," you don't even need to use getElementById() because you're already referring to the div object:

 

this.style.display='block';

 

if you want to stick with the getElementById(), you need to use the document object instead:

 

document.getElementById('ImgDiv1').style.display='block';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.