Skip to content

Instantly share code, notes, and snippets.

@prasadshir
Created September 20, 2013 10:46
Show Gist options
  • Save prasadshir/6635827 to your computer and use it in GitHub Desktop.
Save prasadshir/6635827 to your computer and use it in GitHub Desktop.
Javascript Add Events Listener
window.onload = function(e){
document.getElementById("btn1").addEventListener('dblclick', myAlert);
var li = document.getElementsByTagName("li")
for (i=1;i<li.length; i++){
li[i].addEventListener('mouseover', function(e){
console.log('Hey, you were here!');
console.log(e);
});
}
}
function myAlert(e){
alert('Hey, you clicked!');
console.log(e);
}
<html>
<head>
<title>JS Function Examples</title>
<script src="binding.js" type="text/javascript"></script>
</head>
<body>
<h1>JS Funciton Examples</h1>
<ul id="myList">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<p>This file contains JS examples
<button id="btn1">Click Me!</button>
</p>
<p>This is another para</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment