deadlyp99 Posted October 10, 2008 Share Posted October 10, 2008 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 More sharing options...
JasonLewis Posted October 11, 2008 Share Posted October 11, 2008 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 https://forums.phpfreaks.com/topic/127906-solved-why-wont-this-work/#findComment-662384 Share on other sites More sharing options...
deadlyp99 Posted October 11, 2008 Author Share Posted October 11, 2008 Thanks. Thats the only thing I hate about javascript, case sensitive in a weird way. Thanks for the "this" tip. I knew about it, but I couldn't remember the syntax for it, and didn't want to chance causing even more problems with the code. Link to comment https://forums.phpfreaks.com/topic/127906-solved-why-wont-this-work/#findComment-662531 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.