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
https://forums.phpfreaks.com/topic/127906-solved-why-wont-this-work/
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>
";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.