Skip to content

Instantly share code, notes, and snippets.

@nsisodiya
Created November 3, 2011 10:26
Show Gist options
  • Save nsisodiya/1336211 to your computer and use it in GitHub Desktop.
Save nsisodiya/1336211 to your computer and use it in GitHub Desktop.
Pass Argument to addEventListener
<!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