user4684804
user4684804

Reputation:

Bind multiple events in JavaScript

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

Answers (3)

Dhaval
Dhaval

Reputation: 2379

Forgot Quote..

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

Upvotes: 2

pavel
pavel

Reputation: 27072

You forgot quotes.

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

Upvotes: 2

Radonirina Maminiaina
Radonirina Maminiaina

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

Related Questions