Jump to content

[SOLVED] Why wont this work?


deadlyp99

Recommended Posts

Why wont the following code work? I'm trying to get the image to change on a mouse over, and it simply is not changing :-[

 

The div is returning the mouseover event, so I know that works. I tested with a simple alert. But why it wont change images... I dont know.

 

Thanks for any help.

 

<?php 
echo "
<div id=\"linkbox1\" style=\"position:relative;top:60px;background-image:url('./include/images/link.gif');height:20px;width:50px;\" onmouseover=\"document.getElementById('linkbox1').style.BackgroundImage='url(./include/images/link_over.gif)';\">words</div>
";
?>

Link to comment
Share on other sites

The syntax is this:

 

object.style.backgroundImage='url(hello.gif)'

 

You have:

 

object.style.BackgroundImage='url(hello.gif)'

 

Also, to shorten your code, instead of using getElementById(), since you are changing the current images background image all you need to do is use this.

 

<?php 
echo "
<div id=\"linkbox1\" style=\"position:relative;top:60px;background-image:url('./include/images/link.gif');height:20px;width:50px;\" onmouseover=\"this.style.backgroundImage='url(./include/images/link_over.gif)';\">words</div>
";
?>

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.