Reputation:
I tried the following to change a span to red on mouseover
and black on mouseout
:
<span onmouseover="this.style.color='red' onmouseout=this.style.color='black'">Mouse over me!</span>
but it does not work!
How can I bind more than one event to a single element using JavaScript?
Upvotes: 0
Views: 52
Reputation: 2379
Forgot Quote..
<span onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Mouse over me!</span>
Upvotes: 2
Reputation: 27072
You forgot quotes.
<span onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Mouse over me!</span>
^ ^
Upvotes: 2
Reputation: 7004
You put the onmouseout
into onmouseover
event, it is not correct.
Try this:
<span onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Mouse over me!</span>
Upvotes: 1