Log in

View Full Version : whats wrong with this code?



jmpearson2001
09-04-2006, 12:34 AM
<font color="red"> <span><OnMouseOver="this.style.color="blue"">
hello</span>
</font>

sandman2006
09-04-2006, 01:44 AM
Try this code :)

<font color="red"> <span onmouseover="this.style.color='blue';return false;" onmouseout="this.style.color='red';return false;">
hello
</span></font>

jscheuer1
09-04-2006, 01:47 AM
The font tag for one, it has been deprecated. As a result, its influence over this sort of scheme is unwelcome. In your case, possibly overriding the javascript event. Also, you have quotes within quotes in your event, this will make the browser see your event as:


OnMouseOver="this.style.color="

The event should be an attribute to the span tag, not a separate tag. Camel style notation for mouse events is not required and is not forward compatible. Try:


<span style="color:red;" onmouseover="this.style.color='blue';">
hello</span>

jmpearson2001
09-04-2006, 01:35 PM
ty schuer

jscheuer1
09-04-2006, 04:08 PM
<font color="red"> <span onmouseover="this.style.color='blue';return false;" onmouseout="this.style.color='red';return false;">
hello
</span></font>

Why cling to the deprecated font tag? Why return false? If you want to return the span to its original color on mouse out, I would do this in a style block in the head of the page or in a stylesheet linked to it:


span.h_over {
color:red;
}

Then for the markup:


<span class="h_over" onmouseover="this.style.color='blue';" onmouseout="this.style.color='';">hello</span>