|
0
|
1 |
|
|
|
2 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
|
|
3 |
<html> |
|
|
4 |
<head> |
|
|
5 |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> |
|
|
6 |
<title>Delegating Node Events</title> |
|
|
7 |
|
|
|
8 |
<style type="text/css"> |
|
|
9 |
/*margin and padding on body element |
|
|
10 |
can introduce errors in determining |
|
|
11 |
element position and are not recommended; |
|
|
12 |
we turn them off as a foundation for YUI |
|
|
13 |
CSS treatments. */ |
|
|
14 |
body { |
|
|
15 |
margin:0; |
|
|
16 |
padding:0; |
|
|
17 |
} |
|
|
18 |
</style> |
|
|
19 |
|
|
|
20 |
<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" /> |
|
|
21 |
<script type="text/javascript" src="../../build/yui/yui-min.js"></script> |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
<!--begin custom header content for this example--> |
|
|
25 |
<link href="assets//node.css" rel="stylesheet" type="text/css"> |
|
|
26 |
|
|
|
27 |
<!--end custom header content for this example--> |
|
|
28 |
|
|
|
29 |
</head> |
|
|
30 |
|
|
|
31 |
<body class=" yui-skin-sam"> |
|
|
32 |
|
|
|
33 |
<h1>Delegating Node Events</h1> |
|
|
34 |
|
|
|
35 |
<div class="exampleIntro"> |
|
|
36 |
<p>This example demonstrates using a single event listener on a list to delegate clicks on the list items.</p> |
|
|
37 |
|
|
|
38 |
|
|
|
39 |
</div> |
|
|
40 |
|
|
|
41 |
<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
42 |
|
|
|
43 |
<ul id="demo"> |
|
|
44 |
<li><em>click me if you don't mind...</em></li> |
|
|
45 |
<li><em>click me if you don't mind...</em></li> |
|
|
46 |
<li><em>click me if you don't mind...</em></li> |
|
|
47 |
<li><em>click me if you don't mind...</em></li> |
|
|
48 |
</ul> |
|
|
49 |
|
|
|
50 |
<script type="text/javascript"> |
|
|
51 |
YUI({filter: "debug"}).use("selector-css3", "node", function(Y) { |
|
|
52 |
var nodes = Y.all('#demo li'); |
|
|
53 |
|
|
|
54 |
var onClick = function(e) { |
|
|
55 |
e.currentTarget.addClass('yui-pass'); // e.currentTarget === #demo li |
|
|
56 |
e.target.setContent('thanks for the click!'); // e.target === #demo li or #demo li em |
|
|
57 |
e.container.setStyle('border', '5px solid blue'); // e.container === #demo |
|
|
58 |
|
|
|
59 |
nodes.filter(':not(.yui-pass)').setContent('Click me too please!'); |
|
|
60 |
}; |
|
|
61 |
|
|
|
62 |
Y.one('#demo').delegate('click', onClick, 'li'); |
|
|
63 |
}); |
|
|
64 |
</script> |
|
|
65 |
|
|
|
66 |
<!--END SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
67 |
|
|
|
68 |
</body> |
|
|
69 |
</html> |