Skip to content

Instantly share code, notes, and snippets.

@pujie
Created June 24, 2015 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pujie/248247eb8e9b8302d02e to your computer and use it in GitHub Desktop.
Save pujie/248247eb8e9b8302d02e to your computer and use it in GitHub Desktop.
give event handler to element
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<table id="myTable">
<tr myid=1>
<td> hullo 1</td>
<td class="clickable"> hullo 1</td>
</tr>
</table>
<script type="text/javascript">
(function($){
console.log("hello");
for(var i=2;i<8;i++){
$("#myTable").append('<tr myid='+i+'><td> hullo '+i+'</td><td class="clickable"> hullo '+i+'</td> </tr>');
}
$(".clickable").each(function(){
$(this).click(function(){
console.log("hei",$(this).parent().attr("myid"));
});
});
}(jQuery))
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment