Skip to content

Instantly share code, notes, and snippets.

@ravidaram
Created August 16, 2013 00:26
Show Gist options
  • Save ravidaram/6246200 to your computer and use it in GitHub Desktop.
Save ravidaram/6246200 to your computer and use it in GitHub Desktop.
delegate
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>delegate demo</title>
<style>
td {
background: yellow;
font-weight: bold;
cursor: pointer;
padding: 5px;
}
tr{
background: red;
font-weight: bold;
cursor: pointer;
padding: 5px;
}
}
p.over {
background: #ccc;
}
span {
color: red;
}
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<table>
<tr>
<td> click me to add row</tr>
</tr>
</table>
<span></span>
<script>
$( "table" ).delegate( "tr", "click", function() {
$( this ).after( "<tr> next row </tr>" );
$( "tr" ).delegate( "td", "click", function() {
$( this ).after( "<td> next row </td>" );
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment