Created
April 25, 2012 11:50
-
-
Save leonelag/2489155 to your computer and use it in GitHub Desktop.
Example of how to attach an event to HTML elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<style> | |
li { border: thin solid red } | |
</style> | |
</head> | |
<body> | |
<ul> | |
<li id="my-elem-1">1</li> | |
<li id="my-elem-2">2</li> | |
<li id="my-elem-3">3</li> | |
<li id="my-elem-4">4</li> | |
<li id="my-elem-5">5</li> | |
<li id="my-elem-6">6</li> | |
<li id="my-elem-7">7</li> | |
<li id="my-elem-8">8</li> | |
</ul> | |
<script type="text/javascript"> | |
var items = document.getElementsByTagName("li") | |
for (var i = 0; i < items.length; i++) { | |
var ii = items.item(i); | |
ii.onmouseover = function() { alert(this.id); } | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment