forked from chuanxshi/javascript-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent-delegation.html
More file actions
30 lines (24 loc) · 772 Bytes
/
event-delegation.html
File metadata and controls
30 lines (24 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<!doctype html>
<html lang="en">
<head>
<title>JavaScript Patterns</title>
<meta charset="utf-8">
</head>
<body>
<script>
/* Title: event delegation
Description: event delegation pattern and antipattern
*/
// antipattern
// As of jQuery 1.7, the .live() method is deprecated
// $('a.trigger', $('#container')[0]).live('click', handlerFn);
// preferred
$('#container').on('click', 'a.trigger', handlerFn);
// .bind()
// .live() - best used for simple scenario, it functions the best with a supply selector only, it's not chainable
// .delegate() - it gives you a more focused way, it can better filter the elements, for example, table row
// References
// http://paulirish.com/2009/perf/
</script>
</body>
</html>