|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Node</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
<a href="#toc" class="jump">Jump to Table of Contents</a> |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
<h1>Node</h1> |
|
|
27 |
<div class="yui3-g"> |
|
|
28 |
<div class="yui3-u-3-4"> |
|
|
29 |
<div id="main"> |
|
|
30 |
<div class="content"><div class="intro"> |
|
|
31 |
<p> |
|
|
32 |
The Node Utility provides an expressive way to collect, create, and |
|
|
33 |
manipulate DOM nodes. Each <code>Node</code> instance represents an underlying |
|
|
34 |
DOM node, and each <code>NodeList</code> represents a collection of DOM nodes. |
|
|
35 |
</p> |
|
|
36 |
|
|
|
37 |
<p> |
|
|
38 |
In addition to wrapping the basic DOM API and handling cross browser |
|
|
39 |
issues, <code>Node</code>s provide convenient methods for managing CSS classes, |
|
|
40 |
setting or animating styles, subscribing to events, updating or |
|
|
41 |
dynamically loading content, and lots more. |
|
|
42 |
</p> |
|
|
43 |
|
|
|
44 |
<p> |
|
|
45 |
<strong>Note:</strong><em>The <code>Y.get()</code>, <code>node.query()</code>, and |
|
|
46 |
<code>node.queryAll()</code> methods have been removed. Use <code>Y.one()</code>, |
|
|
47 |
<code>node.one()</code>, and <code>node.all()</code>.</em> |
|
|
48 |
</p> |
|
|
49 |
|
|
|
50 |
</div> |
|
|
51 |
|
|
|
52 |
<h2 id="getting-started">Getting Started</h2> |
|
|
53 |
|
|
|
54 |
<p> |
|
|
55 |
To include the source files for Node and its dependencies, first load |
|
|
56 |
the YUI seed file if you haven't already loaded it. |
|
|
57 |
</p> |
|
|
58 |
|
|
|
59 |
<pre class="code prettyprint"><script src="http://yui.yahooapis.com/3.10.3/build/yui/yui-min.js"></script></pre> |
|
|
60 |
|
|
|
61 |
|
|
|
62 |
<p> |
|
|
63 |
Next, create a new YUI instance for your application and populate it with the |
|
|
64 |
modules you need by specifying them as arguments to the <code>YUI().use()</code> method. |
|
|
65 |
YUI will automatically load any dependencies required by the modules you |
|
|
66 |
specify. |
|
|
67 |
</p> |
|
|
68 |
|
|
|
69 |
<pre class="code prettyprint"><script> |
|
|
70 |
// Create a new YUI instance and populate it with the required modules. |
|
|
71 |
YUI().use('node', function (Y) { |
|
|
72 |
// Node is available and ready for use. Add implementation |
|
|
73 |
// code here. |
|
|
74 |
}); |
|
|
75 |
</script></pre> |
|
|
76 |
|
|
|
77 |
|
|
|
78 |
<p> |
|
|
79 |
For more information on creating YUI instances and on the |
|
|
80 |
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the |
|
|
81 |
documentation for the <a href="../yui/index.html">YUI Global Object</a>. |
|
|
82 |
</p> |
|
|
83 |
|
|
|
84 |
|
|
|
85 |
<h2 id="node-using">Using Nodes</h2> |
|
|
86 |
|
|
|
87 |
<p> |
|
|
88 |
<code>Node</code> is the interface for DOM operations in YUI 3. The Node API is |
|
|
89 |
based on the standard DOM API, and provides additional sugar properties |
|
|
90 |
and methods that make common operations easier, and implementation code |
|
|
91 |
more concise. Developers familiar with the standard DOM API will find |
|
|
92 |
Node instances to be very familiar. |
|
|
93 |
</p> |
|
|
94 |
|
|
|
95 |
<h3 id="using-node">Getting a Node</h3> |
|
|
96 |
|
|
|
97 |
<pre class="code prettyprint">// Use Y.one( [css selector string] ) |
|
|
98 |
var node = Y.one('#main'); |
|
|
99 |
|
|
|
100 |
// Or pass an HTML element |
|
|
101 |
var bodyNode = Y.one(document.body);</pre> |
|
|
102 |
|
|
|
103 |
|
|
|
104 |
<p> |
|
|
105 |
The simplest way to get a <code>Node</code> instance is using your YUI instance's |
|
|
106 |
<code>one</code> method. <code>Y.one</code> accepts either an existing DOM element or a CSS |
|
|
107 |
selector. If a selector string is used, the first matching element is used. |
|
|
108 |
<a href="#nodelist">NodeLists</a> are also available for working with |
|
|
109 |
collections of <code>Node</code>s. |
|
|
110 |
</p> |
|
|
111 |
|
|
|
112 |
<p> |
|
|
113 |
<strong>Note:</strong> CSS3 selector support is not included by default |
|
|
114 |
with Node. Add support by including the "selector-css3" module in your |
|
|
115 |
<code>use()</code> statement. |
|
|
116 |
</p> |
|
|
117 |
|
|
|
118 |
<h3 id="create">Creating Nodes and Modifying Content</h3> |
|
|
119 |
|
|
|
120 |
<pre class="code prettyprint">// Create a new Node |
|
|
121 |
var item = Y.Node.create('<li id="step3" class="highlight"><em>Profit</em></li>'); |
|
|
122 |
|
|
|
123 |
// Replace the content in a Node |
|
|
124 |
Y.one("#hello").setHTML("<h1>Hello, <em>World</em>!</h1>"); |
|
|
125 |
|
|
|
126 |
// Append new markup inside a Node |
|
|
127 |
bodyNode.append("<p>This is the end, beautiful friend, the end.</p>");</pre> |
|
|
128 |
|
|
|
129 |
|
|
|
130 |
<p> |
|
|
131 |
<code>Node</code>s have methods for |
|
|
132 |
<a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_append">appending</a>, |
|
|
133 |
<a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_prepend">prepending</a>, |
|
|
134 |
<a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_setHTML">replacing</a>, and |
|
|
135 |
<a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_insert">inserting</a> |
|
|
136 |
content. The static method |
|
|
137 |
<a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_create"><code>Y.Node.create()</code></a> |
|
|
138 |
is provided to create new <code>Node</code>s that you want to work with a bit more |
|
|
139 |
before attaching them to the DOM. |
|
|
140 |
</p> |
|
|
141 |
|
|
|
142 |
<p> |
|
|
143 |
As noted in <a href="#node-methods">DOM Methods</a> below, the standard DOM |
|
|
144 |
API methods, such as <code>appendChild</code> and <code>insertBefore</code> are also available to |
|
|
145 |
manipulate the DOM structure. |
|
|
146 |
</p> |
|
|
147 |
|
|
|
148 |
<h3 id="node-properties">Accessing Node Properties</h3> |
|
|
149 |
|
|
|
150 |
<pre class="code prettyprint">var imgNode = Y.one('#preview'); |
|
|
151 |
var labelNode = imgNode.get('nextSibling'); // Node instance |
|
|
152 |
|
|
|
153 |
var bigSrc = thumbnail.get('src').slice(0, -4) + '-big.jpg'; |
|
|
154 |
|
|
|
155 |
imgNode.set('src', bigSrc); |
|
|
156 |
imgNode.set('title', thumbnail.get('title'); |
|
|
157 |
labelNode.setHTML(thumbnail.get('title'));</pre> |
|
|
158 |
|
|
|
159 |
<p> |
|
|
160 |
Properties of the underlying DOM node are accessed via the <code>Node</code> |
|
|
161 |
instance's <code>set</code> and <code>get</code> methods. For simple property types (strings, |
|
|
162 |
numbers, booleans), these pass directly to/from the underlying node, but |
|
|
163 |
properties that normally return DOM nodes return <code>Node</code> instances |
|
|
164 |
instead. |
|
|
165 |
</p> |
|
|
166 |
|
|
|
167 |
|
|
|
168 |
<h3 id="node-events">DOM Events</h3> |
|
|
169 |
|
|
|
170 |
<pre class="code prettyprint">Y.one('#demo').on('click', function(e) { |
|
|
171 |
e.preventDefault(); |
|
|
172 |
alert('event: ' + e.type + ' target: ' + e.target.get('tagName')); |
|
|
173 |
});</pre> |
|
|
174 |
|
|
|
175 |
|
|
|
176 |
<p> |
|
|
177 |
Use the <code>on</code> method to add an event listener to a <code>Node</code> instance. The |
|
|
178 |
event object passed as the first argument to each listener is an event |
|
|
179 |
facade that, like the Node API, normalizes browser differences and provides |
|
|
180 |
a standard API for working with DOM events based on the W3C standard. All |
|
|
181 |
properties of the event object that would normally return DOM elements |
|
|
182 |
return <code>Node</code> instances. |
|
|
183 |
</p> |
|
|
184 |
|
|
|
185 |
<p> |
|
|
186 |
For more details, check out <a href="../event/index.html">the Event user |
|
|
187 |
guide</a>. |
|
|
188 |
</p> |
|
|
189 |
|
|
|
190 |
<h3 id="node-methods">DOM Methods</h3> |
|
|
191 |
|
|
|
192 |
<pre class="code prettyprint">var tasklist = Y.one('ul#tasklist'); |
|
|
193 |
var item3 = tasklist.appendChild( Y.one('#pending .item-3') ); |
|
|
194 |
|
|
|
195 |
item3.addClass('highlight');</pre> |
|
|
196 |
|
|
|
197 |
|
|
|
198 |
<p> |
|
|
199 |
The <code>Node</code> API provides all of the DOM methods you would expect, plus a |
|
|
200 |
few extras to help with common tasks. As with properties and events, any |
|
|
201 |
methods that would normally return DOM nodes instead return <code>Node</code> |
|
|
202 |
instances. |
|
|
203 |
</p> |
|
|
204 |
|
|
|
205 |
<h3 id="nodelist">Working With Collections of Nodes</h3> |
|
|
206 |
|
|
|
207 |
<p> |
|
|
208 |
<code>NodeList</code> is the class for working with groups of <code>Node</code>s. |
|
|
209 |
</p> |
|
|
210 |
|
|
|
211 |
<pre class="code prettyprint">var doneTasks = Y.all('#tasklist .completed'); |
|
|
212 |
|
|
|
213 |
// NodeLists host most Node methods for simple iterative operations |
|
|
214 |
doneTasks.removeClass('highlight'); |
|
|
215 |
|
|
|
216 |
// or call each() to do more work on each Node |
|
|
217 |
doneTasks.each(function (taskNode) { |
|
|
218 |
taskNode.transition({ opacity: 0 }, function () { |
|
|
219 |
completedTasklist.appendChild(this); |
|
|
220 |
}); |
|
|
221 |
});</pre> |
|
|
222 |
|
|
|
223 |
|
|
|
224 |
<p> |
|
|
225 |
The <code>Y.all</code> method is the simplest way to get a <code>NodeList</code>, but throughout |
|
|
226 |
the library, any property or method that would return a collection of HTML |
|
|
227 |
elements will return a <code>NodeList</code>. |
|
|
228 |
</p> |
|
|
229 |
|
|
|
230 |
<pre class="code prettyprint">var nodelist = taskList.get('childNodes');</pre> |
|
|
231 |
|
|
|
232 |
|
|
|
233 |
<p> |
|
|
234 |
The <code>NodeList</code> provides a <code>Node</code>-like interface for manipulating multiple |
|
|
235 |
<code>Node</code>s through a single interface. The <code>NodeList</code> API is a pared-down |
|
|
236 |
version of the <code>Node</code> API for simple operations, plus common <code>Array</code> |
|
|
237 |
methods such as |
|
|
238 |
<a href="http://yuilibrary.com/yui/docs/api/classes/NodeList.html#method_slice"><code>slice()</code></a> and |
|
|
239 |
<a href="http://yuilibrary.com/yui/docs/api/classes/NodeList.html#method_pop"><code>pop()</code></a> for |
|
|
240 |
modifying the internal list of wrapped <code>Node</code>s, and some general purpose |
|
|
241 |
iteration methods such as |
|
|
242 |
<a href="http://yuilibrary.com/yui/docs/api/classes/NodeList.html#method_each"><code>each()</code></a> and |
|
|
243 |
<a href="http://yuilibrary.com/yui/docs/api/classes/NodeList.html#method_some"><code>some()</code></a>. |
|
|
244 |
</p> |
|
|
245 |
|
|
|
246 |
|
|
|
247 |
<h3 id="node-query">Query a Node's Descendants</h3> |
|
|
248 |
|
|
|
249 |
<pre class="code prettyprint">var node = Y.one('#demo'); |
|
|
250 |
|
|
|
251 |
var firstPara = node.one('p'); |
|
|
252 |
|
|
|
253 |
if (firstPara) { // might be null |
|
|
254 |
// adds "bar" to the first paragraph descendant of #demo |
|
|
255 |
firstPara.addClass('bar'); |
|
|
256 |
} |
|
|
257 |
|
|
|
258 |
// adds class "syntax-highlight" to all <pre> descendants of #demo |
|
|
259 |
node.all('pre').addClass('syntax-highlight');</pre> |
|
|
260 |
|
|
|
261 |
|
|
|
262 |
<p> |
|
|
263 |
Like <code>Y.one()</code> and <code>Y.all()</code>, <code>Node</code> instances have <code>one()</code> and <code>all()</code> |
|
|
264 |
methods for querying their descendants. |
|
|
265 |
</p> |
|
|
266 |
|
|
|
267 |
<p> |
|
|
268 |
Using selectors to capture descendants is faster and more convenient than |
|
|
269 |
relying on DOM properties such as <code>childNodes</code> and <code>nextSibling</code> since you |
|
|
270 |
don't have to worry about working around text nodes or recursing into |
|
|
271 |
element subtrees. |
|
|
272 |
</p> |
|
|
273 |
<p> |
|
|
274 |
Using <code>one()</code> and <code>all()</code> from a <code>Node</code> rather than <code>Y</code> can aid performance |
|
|
275 |
in large pages as well, because <code>Y.one()</code> and <code>Y.all()</code> always query from |
|
|
276 |
the <code>document</code>, which will scan a lot more elements. |
|
|
277 |
</p> |
|
|
278 |
|
|
|
279 |
<p> |
|
|
280 |
For more information on selector queries, see the following W3C |
|
|
281 |
specifications: |
|
|
282 |
</p> |
|
|
283 |
|
|
|
284 |
<ul> |
|
|
285 |
<li><a href="http://www.w3.org/TR/css3-selectors/">CSS Level 3 Selectors</a></li> |
|
|
286 |
<li><a href="http://www.w3.org/TR/selectors-API/">Selectors API</a></li> |
|
|
287 |
</ul> |
|
|
288 |
|
|
|
289 |
<p> |
|
|
290 |
<strong>Note:</strong> CSS3 selector support is not included by default |
|
|
291 |
with Node, you will need to include the "selector-css3" module for CSS3 |
|
|
292 |
support. |
|
|
293 |
</p> |
|
|
294 |
|
|
|
295 |
|
|
|
296 |
<h2 id="node-aria">ARIA Support</h2> |
|
|
297 |
|
|
|
298 |
<p> |
|
|
299 |
The Node interface has support for <a |
|
|
300 |
href="http://www.w3.org/TR/wai-aria/">ARIA</a>. When used with Node's |
|
|
301 |
built-in support for CSS selector queries, it is easy to both apply and |
|
|
302 |
manage a Node's <a href="http://www.w3.org/TR/wai-aria/#roles">roles</a>, |
|
|
303 |
<a href="http://www.w3.org/TR/wai-aria/#supportedState">states and |
|
|
304 |
properties</a>. |
|
|
305 |
<p> |
|
|
306 |
|
|
|
307 |
<p> |
|
|
308 |
The ARIA Roles, States and Properties enhance the semantics of HTML, |
|
|
309 |
allowing developers to more accurately describe the intended purpose of a |
|
|
310 |
region of a page, or a DHTML widget, thereby improving the user experience |
|
|
311 |
for users of assistive technology, such as screen readers. |
|
|
312 |
</p> |
|
|
313 |
|
|
|
314 |
<p> |
|
|
315 |
Apply any of the ARIA Roles, States and Properties via the <code>set</code> method. |
|
|
316 |
For example, to apply the role of <a |
|
|
317 |
href="http://www.w3.org/TR/wai-aria/#toolbar"><code>toolbar</code></a> to a <code><div></code> |
|
|
318 |
with an id of "toolbar": |
|
|
319 |
</p> |
|
|
320 |
|
|
|
321 |
<pre class="code prettyprint">var node = Y.one('#toolbar').set('role', 'toolbar');</pre> |
|
|
322 |
|
|
|
323 |
|
|
|
324 |
<p> |
|
|
325 |
Node's built-in support for CSS selector queries, method chaining, and |
|
|
326 |
ability to set multiple attributes on a single Node instance makes it |
|
|
327 |
especially easy to apply the ARIA Roles, States, and Properties when |
|
|
328 |
building DHTML widgets with a large subtree. For example, when building a |
|
|
329 |
menubar widget it is necessary to apply a role of |
|
|
330 |
<a href="http://www.w3.org/TR/wai-aria/#menubar"><code>menubar</code></a> to the root |
|
|
331 |
DOM element representing the menubar, and the role of |
|
|
332 |
<a href="http://www.w3.org/TR/wai-aria/#menu"><code>menu</code></a> to the root DOM |
|
|
333 |
element representing each submenu. Additionally, as each submenu is hidden |
|
|
334 |
by default, the |
|
|
335 |
<a href="http://www.w3.org/TR/wai-aria/#aria-"><code>aria-hidden</code></a> state will |
|
|
336 |
need to be applied to each submenu as well. The Node interface makes it |
|
|
337 |
possible to do all of this in one line of code: |
|
|
338 |
</p> |
|
|
339 |
|
|
|
340 |
<pre class="code prettyprint">Y.one('#root').set('role', 'menubar').all('.menu').setAttrs({ role: 'menu', 'aria-hidden': true });</pre> |
|
|
341 |
|
|
|
342 |
|
|
|
343 |
<h2 id="node-migration">Migration Table</h2> |
|
|
344 |
|
|
|
345 |
<p> |
|
|
346 |
The following table is included to help users migrating from YUI 2. Most |
|
|
347 |
of the functionality from <code>YAHOO.util.Dom</code> is available via <code>Node</code>. |
|
|
348 |
</p> |
|
|
349 |
|
|
|
350 |
<p> |
|
|
351 |
<strong>Note</strong> In the snippets below, <code>myNode</code> is an instance of |
|
|
352 |
<code>Node</code>. Methods that normally would return DOM nodes now return Node |
|
|
353 |
instances. |
|
|
354 |
</p> |
|
|
355 |
|
|
|
356 |
<table class="yui-table"> |
|
|
357 |
<thead> |
|
|
358 |
<tr> |
|
|
359 |
<th>2.x <code>YAHOO.util.???</code></th> |
|
|
360 |
<th>3.0</th> |
|
|
361 |
</tr> |
|
|
362 |
</thead> |
|
|
363 |
<tbody> |
|
|
364 |
<tr> |
|
|
365 |
<td> |
|
|
366 |
<pre class="code prettyprint">Dom.get('elementId');</pre> |
|
|
367 |
|
|
|
368 |
</td> |
|
|
369 |
<td> |
|
|
370 |
<pre class="code prettyprint">Y.one('#elementId');</pre> |
|
|
371 |
|
|
|
372 |
</td> |
|
|
373 |
</tr> |
|
|
374 |
<tr> |
|
|
375 |
<td> |
|
|
376 |
<pre class="code prettyprint">Dom.getElementsBy(someFilterFunction);</pre> |
|
|
377 |
|
|
|
378 |
</td> |
|
|
379 |
<td> |
|
|
380 |
<pre class="code prettyprint">myNode.all('selectorString');</pre> |
|
|
381 |
|
|
|
382 |
</td> |
|
|
383 |
</tr> |
|
|
384 |
<tr> |
|
|
385 |
<td> |
|
|
386 |
<pre class="code prettyprint">Dom.getElementsByClassName('highlight');</pre> |
|
|
387 |
|
|
|
388 |
</td> |
|
|
389 |
<td> |
|
|
390 |
<pre class="code prettyprint">myNode.all('.highlight');</pre> |
|
|
391 |
|
|
|
392 |
</td> |
|
|
393 |
</tr> |
|
|
394 |
<tr> |
|
|
395 |
<td> |
|
|
396 |
<pre class="code prettyprint">Dom.getChildren(el);</pre> |
|
|
397 |
|
|
|
398 |
</td> |
|
|
399 |
<td> |
|
|
400 |
<pre class="code prettyprint">myNode.get('children');</pre> |
|
|
401 |
|
|
|
402 |
</td> |
|
|
403 |
</tr> |
|
|
404 |
<tr> |
|
|
405 |
<td> |
|
|
406 |
<pre class="code prettyprint">Dom.getChildrenBy(someFilterFunction);</pre> |
|
|
407 |
|
|
|
408 |
</td> |
|
|
409 |
<td> |
|
|
410 |
<pre class="code prettyprint">myNode.all('selectorString');</pre> |
|
|
411 |
|
|
|
412 |
</td> |
|
|
413 |
</tr> |
|
|
414 |
<tr> |
|
|
415 |
<td> |
|
|
416 |
<pre class="code prettyprint">Dom.getFirstChild(parentEl);</pre> |
|
|
417 |
|
|
|
418 |
</td> |
|
|
419 |
<td> |
|
|
420 |
<pre class="code prettyprint">myNode.one('*');</pre> |
|
|
421 |
|
|
|
422 |
</td> |
|
|
423 |
</tr> |
|
|
424 |
<tr> |
|
|
425 |
<td> |
|
|
426 |
<pre class="code prettyprint">Dom.getFirstChildBy(someFilterFunction);</pre> |
|
|
427 |
|
|
|
428 |
</td> |
|
|
429 |
<td> |
|
|
430 |
<pre class="code prettyprint">myNode.one('> selectorString');</pre> |
|
|
431 |
|
|
|
432 |
</td> |
|
|
433 |
</tr> |
|
|
434 |
<tr> |
|
|
435 |
<td> |
|
|
436 |
<pre class="code prettyprint">Dom.getLastChild(el); |
|
|
437 |
Dom.getLastChildBy(someFilterFunction);</pre> |
|
|
438 |
|
|
|
439 |
</td> |
|
|
440 |
<td> |
|
|
441 |
<pre class="code prettyprint">myNode.get('children').slice(-1).item(0); |
|
|
442 |
// OR target the node with a selector |
|
|
443 |
myNode.one('> selector:last-of-type');</pre> |
|
|
444 |
|
|
|
445 |
</td> |
|
|
446 |
</tr> |
|
|
447 |
<tr> |
|
|
448 |
<td> |
|
|
449 |
<pre class="code prettyprint">Dom.getNextSibling(el); |
|
|
450 |
Dom.getNextSiblingBy(someFilterFunction); |
|
|
451 |
Dom.getPreviousSibling(el); |
|
|
452 |
Dom.getPreviousSiblingBy(someFilterFunction);</pre> |
|
|
453 |
|
|
|
454 |
</td> |
|
|
455 |
<td> |
|
|
456 |
<pre class="code prettyprint">myNode.next(); |
|
|
457 |
myNode.next('selectorString'); |
|
|
458 |
myNode.previous(); |
|
|
459 |
myNode.previous('selectorString');</pre> |
|
|
460 |
|
|
|
461 |
</td> |
|
|
462 |
</tr> |
|
|
463 |
<tr> |
|
|
464 |
<td> |
|
|
465 |
<pre class="code prettyprint">Dom.getAncestorBy(someFilterFunction); |
|
|
466 |
Dom.getAncestorByClassName('highlight'); |
|
|
467 |
Dom.getAncestorByTagName('pre');</pre> |
|
|
468 |
|
|
|
469 |
</td> |
|
|
470 |
<td> |
|
|
471 |
<pre class="code prettyprint">myNode.ancestor(someFilterFunction); |
|
|
472 |
myNode.ancestor('.highlight'); |
|
|
473 |
myNode.ancestor('pre');</pre> |
|
|
474 |
|
|
|
475 |
</td> |
|
|
476 |
</tr> |
|
|
477 |
<tr> |
|
|
478 |
<td> |
|
|
479 |
<pre class="code prettyprint">Dom.isAncestor(ancestorEl, el);</pre> |
|
|
480 |
|
|
|
481 |
</td> |
|
|
482 |
<td> |
|
|
483 |
<pre class="code prettyprint">ancestorNode.contains(myNode);</pre> |
|
|
484 |
|
|
|
485 |
</td> |
|
|
486 |
</tr> |
|
|
487 |
<tr> |
|
|
488 |
<td> |
|
|
489 |
<pre class="code prettyprint">Dom.insertAfter(el, afterEl); |
|
|
490 |
Dom.insertBefore(el, beforeNode);</pre> |
|
|
491 |
|
|
|
492 |
</td> |
|
|
493 |
<td> |
|
|
494 |
<pre class="code prettyprint">afterNode.insert(myNode, 'after'); |
|
|
495 |
beforeNode.insert(myNode, 'before');</pre> |
|
|
496 |
|
|
|
497 |
</td> |
|
|
498 |
</tr> |
|
|
499 |
<tr> |
|
|
500 |
<td> |
|
|
501 |
<pre class="code prettyprint">Dom.addClass('highlight');</pre> |
|
|
502 |
|
|
|
503 |
</td> |
|
|
504 |
<td> |
|
|
505 |
<pre class="code prettyprint">myNode.addClass('highlight');</pre> |
|
|
506 |
|
|
|
507 |
</td> |
|
|
508 |
</tr> |
|
|
509 |
<tr> |
|
|
510 |
<td> |
|
|
511 |
<pre class="code prettyprint">Dom.removeClass(el, 'highlight');</pre> |
|
|
512 |
|
|
|
513 |
</td> |
|
|
514 |
<td> |
|
|
515 |
<pre class="code prettyprint">myNode.removeClass('highlight');</pre> |
|
|
516 |
|
|
|
517 |
</td> |
|
|
518 |
</tr> |
|
|
519 |
<tr> |
|
|
520 |
<td> |
|
|
521 |
<pre class="code prettyprint">Dom.replaceClass(el, 'high', 'low');</pre> |
|
|
522 |
|
|
|
523 |
</td> |
|
|
524 |
<td> |
|
|
525 |
<pre class="code prettyprint">myNode.replaceClass('high', 'low');</pre> |
|
|
526 |
|
|
|
527 |
</td> |
|
|
528 |
</tr> |
|
|
529 |
<tr> |
|
|
530 |
<td> |
|
|
531 |
<pre class="code prettyprint">Dom.hasClass(el, 'highlight');</pre> |
|
|
532 |
|
|
|
533 |
</td> |
|
|
534 |
<td> |
|
|
535 |
<pre class="code prettyprint">myNode.hasClass('highlight');</pre> |
|
|
536 |
|
|
|
537 |
</td> |
|
|
538 |
</tr> |
|
|
539 |
<tr> |
|
|
540 |
<td> |
|
|
541 |
<pre class="code prettyprint">Dom.getStyle(el, 'backgroundColor');</pre> |
|
|
542 |
|
|
|
543 |
</td> |
|
|
544 |
<td> |
|
|
545 |
<pre class="code prettyprint">myNode.getStyle('backgroundColor');</pre> |
|
|
546 |
|
|
|
547 |
</td> |
|
|
548 |
</tr> |
|
|
549 |
<tr> |
|
|
550 |
<td> |
|
|
551 |
<pre class="code prettyprint">Dom.setStyle(el, 'borderColor', '#C0FFEE');</pre> |
|
|
552 |
|
|
|
553 |
</td> |
|
|
554 |
<td> |
|
|
555 |
<pre class="code prettyprint">myNode.setStyle('borderColor', '#C0FFEE');</pre> |
|
|
556 |
|
|
|
557 |
</td> |
|
|
558 |
</tr> |
|
|
559 |
<tr> |
|
|
560 |
<td> |
|
|
561 |
<pre class="code prettyprint">Dom.getXY(el); |
|
|
562 |
Dom.getX(el); |
|
|
563 |
Dom.getY(el);</pre> |
|
|
564 |
|
|
|
565 |
</td> |
|
|
566 |
<td> |
|
|
567 |
<pre class="code prettyprint">myNode.getXY(); |
|
|
568 |
myNode.getX(); |
|
|
569 |
myNode.getY();</pre> |
|
|
570 |
|
|
|
571 |
</td> |
|
|
572 |
</tr> |
|
|
573 |
<tr> |
|
|
574 |
<td> |
|
|
575 |
<pre class="code prettyprint">Dom.setXY(el, [ 500, 300 ]); |
|
|
576 |
Dom.setX(el, 500); |
|
|
577 |
Dom.setY(el, 300);</pre> |
|
|
578 |
|
|
|
579 |
</td> |
|
|
580 |
<td> |
|
|
581 |
<pre class="code prettyprint">myNode.setXY([ 500, 300 ]); |
|
|
582 |
myNode.setX(500); |
|
|
583 |
myNode.setY(300);</pre> |
|
|
584 |
|
|
|
585 |
</td> |
|
|
586 |
</tr> |
|
|
587 |
<tr> |
|
|
588 |
<td> |
|
|
589 |
<pre class="code prettyprint">Dom.inDocument(el);</pre> |
|
|
590 |
|
|
|
591 |
</td> |
|
|
592 |
<td> |
|
|
593 |
<pre class="code prettyprint">myNode.inDoc();</pre> |
|
|
594 |
|
|
|
595 |
</td> |
|
|
596 |
</tr> |
|
|
597 |
<tr> |
|
|
598 |
<td> |
|
|
599 |
<pre class="code prettyprint">Dom.batch(elementArray, |
|
|
600 |
Dom.addClass, 'highlight');</pre> |
|
|
601 |
|
|
|
602 |
</td> |
|
|
603 |
<td> |
|
|
604 |
<pre class="code prettyprint">myNodelist.addClass('highlight'); |
|
|
605 |
// OR |
|
|
606 |
myNodelist.each(function (node) { |
|
|
607 |
node.addClass('highlight') |
|
|
608 |
}); |
|
|
609 |
// OR |
|
|
610 |
Y.Array.each(myNodelist, function (node) { |
|
|
611 |
node.addClass('highlight'); |
|
|
612 |
});</pre> |
|
|
613 |
|
|
|
614 |
</td> |
|
|
615 |
</tr> |
|
|
616 |
<tr> |
|
|
617 |
<td> |
|
|
618 |
<pre class="code prettyprint">Dom.generateId();</pre> |
|
|
619 |
|
|
|
620 |
</td> |
|
|
621 |
<td> |
|
|
622 |
<pre class="code prettyprint">Y.guid();</pre> |
|
|
623 |
|
|
|
624 |
</td> |
|
|
625 |
</tr> |
|
|
626 |
<tr> |
|
|
627 |
<td> |
|
|
628 |
<pre class="code prettyprint">Dom.getViewportHeight(); |
|
|
629 |
Dom.getViewportWidth();</pre> |
|
|
630 |
|
|
|
631 |
</td> |
|
|
632 |
<td> |
|
|
633 |
<pre class="code prettyprint">myNode.get('winHeight'); |
|
|
634 |
myNode.get('winWidth');</pre> |
|
|
635 |
|
|
|
636 |
</td> |
|
|
637 |
</tr> |
|
|
638 |
<tr> |
|
|
639 |
<td> |
|
|
640 |
<pre class="code prettyprint">Dom.getDocumentHeight(); |
|
|
641 |
Dom.getDocumentWidth();</pre> |
|
|
642 |
|
|
|
643 |
</td> |
|
|
644 |
<td> |
|
|
645 |
<pre class="code prettyprint">myNode.get('docHeight'); |
|
|
646 |
myNode.get('docWidth');</pre> |
|
|
647 |
|
|
|
648 |
</td> |
|
|
649 |
</tr> |
|
|
650 |
<tr> |
|
|
651 |
<td> |
|
|
652 |
<pre class="code prettyprint">Dom.getClientRegion();</pre> |
|
|
653 |
|
|
|
654 |
</td> |
|
|
655 |
<td> |
|
|
656 |
<pre class="code prettyprint">myNode.get('viewportRegion');</pre> |
|
|
657 |
|
|
|
658 |
</td> |
|
|
659 |
</tr> |
|
|
660 |
<tr> |
|
|
661 |
<td> |
|
|
662 |
<pre class="code prettyprint">Dom.getRegion(el);</pre> |
|
|
663 |
|
|
|
664 |
</td> |
|
|
665 |
<td> |
|
|
666 |
<pre class="code prettyprint">myNode.get('region');</pre> |
|
|
667 |
|
|
|
668 |
</td> |
|
|
669 |
</tr> |
|
|
670 |
<tr> |
|
|
671 |
<td> |
|
|
672 |
<pre class="code prettyprint">Dom.getDocumentScrollLeft(); |
|
|
673 |
Dom.getDocumentScrollTop();</pre> |
|
|
674 |
|
|
|
675 |
</td> |
|
|
676 |
<td> |
|
|
677 |
<pre class="code prettyprint">myNode.get('docScrollX'); |
|
|
678 |
myNode.get('docScrollY');</pre> |
|
|
679 |
|
|
|
680 |
</td> |
|
|
681 |
</tr> |
|
|
682 |
</tbody> |
|
|
683 |
</table> |
|
|
684 |
</div> |
|
|
685 |
</div> |
|
|
686 |
</div> |
|
|
687 |
|
|
|
688 |
<div class="yui3-u-1-4"> |
|
|
689 |
<div class="sidebar"> |
|
|
690 |
|
|
|
691 |
<div id="toc" class="sidebox"> |
|
|
692 |
<div class="hd"> |
|
|
693 |
<h2 class="no-toc">Table of Contents</h2> |
|
|
694 |
</div> |
|
|
695 |
|
|
|
696 |
<div class="bd"> |
|
|
697 |
<ul class="toc"> |
|
|
698 |
<li> |
|
|
699 |
<a href="#getting-started">Getting Started</a> |
|
|
700 |
</li> |
|
|
701 |
<li> |
|
|
702 |
<a href="#node-using">Using Nodes</a> |
|
|
703 |
<ul class="toc"> |
|
|
704 |
<li> |
|
|
705 |
<a href="#using-node">Getting a Node</a> |
|
|
706 |
</li> |
|
|
707 |
<li> |
|
|
708 |
<a href="#create">Creating Nodes and Modifying Content</a> |
|
|
709 |
</li> |
|
|
710 |
<li> |
|
|
711 |
<a href="#node-properties">Accessing Node Properties</a> |
|
|
712 |
</li> |
|
|
713 |
<li> |
|
|
714 |
<a href="#node-events">DOM Events</a> |
|
|
715 |
</li> |
|
|
716 |
<li> |
|
|
717 |
<a href="#node-methods">DOM Methods</a> |
|
|
718 |
</li> |
|
|
719 |
<li> |
|
|
720 |
<a href="#nodelist">Working With Collections of Nodes</a> |
|
|
721 |
</li> |
|
|
722 |
<li> |
|
|
723 |
<a href="#node-query">Query a Node's Descendants</a> |
|
|
724 |
</li> |
|
|
725 |
</ul> |
|
|
726 |
</li> |
|
|
727 |
<li> |
|
|
728 |
<a href="#node-aria">ARIA Support</a> |
|
|
729 |
</li> |
|
|
730 |
<li> |
|
|
731 |
<a href="#node-migration">Migration Table</a> |
|
|
732 |
</li> |
|
|
733 |
</ul> |
|
|
734 |
</div> |
|
|
735 |
</div> |
|
|
736 |
|
|
|
737 |
|
|
|
738 |
|
|
|
739 |
<div class="sidebox"> |
|
|
740 |
<div class="hd"> |
|
|
741 |
<h2 class="no-toc">Examples</h2> |
|
|
742 |
</div> |
|
|
743 |
|
|
|
744 |
<div class="bd"> |
|
|
745 |
<ul class="examples"> |
|
|
746 |
|
|
|
747 |
|
|
|
748 |
<li data-description="Using selectors and property accessors with Node."> |
|
|
749 |
<a href="properties.html">Set and Get Properties</a> |
|
|
750 |
</li> |
|
|
751 |
|
|
|
752 |
|
|
|
753 |
|
|
|
754 |
<li data-description="Using DOM methods with Node."> |
|
|
755 |
<a href="dom-node.html">DOM Methods</a> |
|
|
756 |
</li> |
|
|
757 |
|
|
|
758 |
|
|
|
759 |
|
|
|
760 |
<li data-description="Building a simple store and shopping cart."> |
|
|
761 |
<a href="store.html">DOM Methods - Store</a> |
|
|
762 |
</li> |
|
|
763 |
|
|
|
764 |
|
|
|
765 |
|
|
|
766 |
<li data-description="Listening for DOM events with Node instances."> |
|
|
767 |
<a href="events.html">Handling DOM Events</a> |
|
|
768 |
</li> |
|
|
769 |
|
|
|
770 |
|
|
|
771 |
|
|
|
772 |
<li data-description="NodeList provides Node functionality for manipulating multiple nodes at once."> |
|
|
773 |
<a href="nodelist.html">Using NodeList - Simple</a> |
|
|
774 |
</li> |
|
|
775 |
|
|
|
776 |
|
|
|
777 |
|
|
|
778 |
<li data-description="How to use multiple NodeList features to build a simple game."> |
|
|
779 |
<a href="ducks.html">Using NodeList - Ducks Game</a> |
|
|
780 |
</li> |
|
|
781 |
|
|
|
782 |
|
|
|
783 |
|
|
|
784 |
<li data-description="Using a single event listener to handle events on multiple nodes."> |
|
|
785 |
<a href="node-evt-delegation.html">Delegating Node Events</a> |
|
|
786 |
</li> |
|
|
787 |
|
|
|
788 |
|
|
|
789 |
|
|
|
790 |
<li data-description="This example demonstrates how to position an element in page coordinates."> |
|
|
791 |
<a href="node-xy.html">Node Positioning</a> |
|
|
792 |
</li> |
|
|
793 |
|
|
|
794 |
|
|
|
795 |
|
|
|
796 |
<li data-description="This example demonstrates how to set styles and get style information."> |
|
|
797 |
<a href="node-style.html">Node Styling</a> |
|
|
798 |
</li> |
|
|
799 |
|
|
|
800 |
|
|
|
801 |
|
|
|
802 |
<li data-description="This example demonstrates how to insert content into a Node."> |
|
|
803 |
<a href="node-insert.html">Adding Node Content - Burger Builder</a> |
|
|
804 |
</li> |
|
|
805 |
|
|
|
806 |
|
|
|
807 |
|
|
|
808 |
<li data-description="This example demonstrates how to show and hide a Node."> |
|
|
809 |
<a href="node-view.html">Showing and Hiding</a> |
|
|
810 |
</li> |
|
|
811 |
|
|
|
812 |
|
|
|
813 |
|
|
|
814 |
|
|
|
815 |
|
|
|
816 |
|
|
|
817 |
|
|
|
818 |
|
|
|
819 |
|
|
|
820 |
|
|
|
821 |
|
|
|
822 |
|
|
|
823 |
|
|
|
824 |
|
|
|
825 |
|
|
|
826 |
|
|
|
827 |
</ul> |
|
|
828 |
</div> |
|
|
829 |
</div> |
|
|
830 |
|
|
|
831 |
|
|
|
832 |
|
|
|
833 |
<div class="sidebox"> |
|
|
834 |
<div class="hd"> |
|
|
835 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
836 |
</div> |
|
|
837 |
|
|
|
838 |
<div class="bd"> |
|
|
839 |
<ul class="examples"> |
|
|
840 |
|
|
|
841 |
|
|
|
842 |
|
|
|
843 |
|
|
|
844 |
|
|
|
845 |
|
|
|
846 |
|
|
|
847 |
|
|
|
848 |
|
|
|
849 |
|
|
|
850 |
|
|
|
851 |
|
|
|
852 |
|
|
|
853 |
|
|
|
854 |
|
|
|
855 |
|
|
|
856 |
|
|
|
857 |
|
|
|
858 |
|
|
|
859 |
|
|
|
860 |
|
|
|
861 |
|
|
|
862 |
|
|
|
863 |
|
|
|
864 |
<li data-description="Creating an accessible toolbar using the Focus Manager Node Plugin and Node's support for the WAI-ARIA Roles and States."> |
|
|
865 |
<a href="../node-focusmanager/node-focusmanager-toolbar.html">Accessible Toolbar</a> |
|
|
866 |
</li> |
|
|
867 |
|
|
|
868 |
|
|
|
869 |
|
|
|
870 |
<li data-description="Creating an accessible menu button using the Focus Manager Node Plugin, Event's delegation support and mouseenter event, along with the Overlay widget and Node's support for the WAI-ARIA Roles and States."> |
|
|
871 |
<a href="../node-focusmanager/node-focusmanager-button.html">Accessible Menu Button</a> |
|
|
872 |
</li> |
|
|
873 |
|
|
|
874 |
|
|
|
875 |
|
|
|
876 |
<li data-description="Use the Event Utility to attach simple DOM event handlers."> |
|
|
877 |
<a href="../event/basic-example.html">Simple DOM Events</a> |
|
|
878 |
</li> |
|
|
879 |
|
|
|
880 |
|
|
|
881 |
|
|
|
882 |
<li data-description="Example Photo Browser application."> |
|
|
883 |
<a href="../dd/photo-browser.html">Photo Browser</a> |
|
|
884 |
</li> |
|
|
885 |
|
|
|
886 |
|
|
|
887 |
|
|
|
888 |
<li data-description="Portal style example using Drag & Drop Event Bubbling and Animation."> |
|
|
889 |
<a href="../dd/portal-drag.html">Portal Style Example</a> |
|
|
890 |
</li> |
|
|
891 |
|
|
|
892 |
|
|
|
893 |
|
|
|
894 |
<li data-description="Use IO to request XML data from a remote web service."> |
|
|
895 |
<a href="../io/weather.html">Request XML data from Yahoo! Weather</a> |
|
|
896 |
</li> |
|
|
897 |
|
|
|
898 |
|
|
|
899 |
|
|
|
900 |
<li data-description="Use IO to make a cross-domain request to Yahoo! Pipes, returning data from disparate sources."> |
|
|
901 |
<a href="../io/xdr.html">Request JSON using Yahoo! Pipes</a> |
|
|
902 |
</li> |
|
|
903 |
|
|
|
904 |
|
|
|
905 |
</ul> |
|
|
906 |
</div> |
|
|
907 |
</div> |
|
|
908 |
|
|
|
909 |
</div> |
|
|
910 |
</div> |
|
|
911 |
</div> |
|
|
912 |
</div> |
|
|
913 |
|
|
|
914 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
915 |
<script>prettyPrint();</script> |
|
|
916 |
|
|
|
917 |
<script> |
|
|
918 |
YUI.Env.Tests = { |
|
|
919 |
examples: [], |
|
|
920 |
project: '../assets', |
|
|
921 |
assets: '../assets/node', |
|
|
922 |
name: 'node', |
|
|
923 |
title: 'Node', |
|
|
924 |
newWindow: '', |
|
|
925 |
auto: false |
|
|
926 |
}; |
|
|
927 |
YUI.Env.Tests.examples.push('properties'); |
|
|
928 |
YUI.Env.Tests.examples.push('dom-node'); |
|
|
929 |
YUI.Env.Tests.examples.push('store'); |
|
|
930 |
YUI.Env.Tests.examples.push('events'); |
|
|
931 |
YUI.Env.Tests.examples.push('nodelist'); |
|
|
932 |
YUI.Env.Tests.examples.push('ducks'); |
|
|
933 |
YUI.Env.Tests.examples.push('node-evt-delegation'); |
|
|
934 |
YUI.Env.Tests.examples.push('node-xy'); |
|
|
935 |
YUI.Env.Tests.examples.push('node-style'); |
|
|
936 |
YUI.Env.Tests.examples.push('node-insert'); |
|
|
937 |
YUI.Env.Tests.examples.push('node-view'); |
|
|
938 |
YUI.Env.Tests.examples.push('node-focusmanager-toolbar'); |
|
|
939 |
YUI.Env.Tests.examples.push('node-focusmanager-button'); |
|
|
940 |
YUI.Env.Tests.examples.push('basic-example'); |
|
|
941 |
YUI.Env.Tests.examples.push('photo-browser'); |
|
|
942 |
YUI.Env.Tests.examples.push('portal-drag'); |
|
|
943 |
YUI.Env.Tests.examples.push('weather'); |
|
|
944 |
YUI.Env.Tests.examples.push('xdr'); |
|
|
945 |
|
|
|
946 |
</script> |
|
|
947 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
948 |
|
|
|
949 |
|
|
|
950 |
|
|
|
951 |
</body> |
|
|
952 |
</html> |