Click to See Complete Forum and Search --> : HTML tag for onMouseOver Event?


manutdfan
03-02-2009, 05:19 PM
Like the title says I have got an onMouseOver event working, however when I validate the page it fails stating that <a> tags do not have this event, it also doesn't like the onMouseOut part and the name bit in the <img> tag.

The main reason I am doing this is to pass to a small javascript piece which replaces the image when moused over and return it back to normal when the mouse has disappeared. I am trying to code within the standards but I cannot find any examples of such code on the w3c website.

thanks

<a href="/index.html" onMouseOver="sel('home')" onMouseOut="notSel('home')">
<img src="/images/home.png" alt="Homepage" class="sidebar" name="home"/>
</a>

function sel(name)
{
document.images[name].src = "/images/" + name + "Sel.png";
}

function notSel(name)
{
document.images[name].src = "/images/" + name + ".png";
}

miniCarl
03-02-2009, 05:36 PM
Yeah you should probably make that a <div> with the image as a background-atribute.
Then u can use the hover-pseudo in CSS to change the image

Charles
03-02-2009, 05:55 PM
See http://www.alistapart.com/articles/sprites/ for a way better way to do an image swap on a rollover.

Your validation issue comes from your use of XHTML. It's an "onmouseover" attribute not "onMouseOver". XHTML is case sensitive. It's also likely completely unnecessary in your instance so you might want to switch to HTML.

highthere
03-05-2009, 11:23 PM
Dont use HTML, nobody should be using HTML...