Created
November 3, 2011 10:26
-
-
Save nsisodiya/1336211 to your computer and use it in GitHub Desktop.
Pass Argument to addEventListener
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>HTML5</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
<script type="text/javascript"> | |
function fun1(){ | |
Arr = ["A","B","C","D","E"]; | |
for (var i = 0 ; i<Arr.length; i++){ | |
document.getElementById(Arr[i]).addEventListener("click", | |
(function(eleid){ | |
return function(){ | |
alert("U clicked " + eleid); | |
} | |
} | |
)(Arr[i]), false); | |
} | |
} | |
window.onload = fun1; | |
</script> | |
</head> | |
<body> | |
<input type="button" value="A" id="A"></input> | |
<input type="button" value="B" id="B"></input> | |
<input type="button" value="C" id="C"></input> | |
<input type="button" value="D" id="D"></input> | |
<input type="button" value="E" id="E"></input> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment