HomeMathComputingArtsWordsLiteratureMusictwitter facebook webfeed

Javascript OnMouseOver Example

Xah Lee, 2005, 2010-10-21

Advertise Here For Profit

The following is a simple event example:

Move your mouse On Me!

Here's the html code:

<p>Move your mouse <span id="x0c6fc" class="x0f205">On Me</span>!</p>

Following is the css code:

.x0f205 {border:solid thin; background-color:yellow}

Following is the javascript code:

document.getElementById("x0c6fc").onmouseover = function () {alert('You moused over me!');} ;

This is a simple example of a Event. The event is “onMouseOver”, attached to the “span” tag. When user moves the mouse over the word, the browser detects it and fires the event, then calls the javascript function (the event handler) attached with that event. In this case, the code is just 「alert('You moused over me!');」.

blog comments powered by Disqus