0

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?

1
  • 2
    You are not closing your double quotes. Try this: <span onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Mouse over me!</span> Commented May 12, 2015 at 7:37

3 Answers 3

2

Forgot Quote..

<span onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Mouse over me!</span>

Sign up to request clarification or add additional context in comments.

Comments

2

You forgot quotes.

<span onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Mouse over me!</span>
                                         ^            ^

Comments

1

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.