Skip to content

Commit fc8de53

Browse files
andylikswedberg
authored andcommitted
Split .get() into 2 separate entries
1 parent 8f055c0 commit fc8de53

1 file changed

Lines changed: 98 additions & 82 deletions

File tree

entries/get.xml

Lines changed: 98 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,103 @@
11
<?xml version="1.0"?>
2-
<entry type="method" name="get">
3-
<return type="Element"/>
4-
<return type="Array"/>
5-
<title>.get()</title>
6-
<signature>
7-
<added>1.0</added>
8-
<argument name="index" type="Integer">
9-
<desc>A zero-based integer indicating which element to retrieve.</desc>
10-
</argument>
11-
</signature>
12-
<signature>
13-
<added>1.0</added>
14-
</signature>
2+
<entries>
153
<desc>Retrieve the DOM elements matched by the jQuery object.</desc>
16-
<longdesc>
17-
<p>The <code>.get()</code> method grants us access to the DOM nodes underlying each jQuery object. Consider a simple unordered list:</p>
18-
<pre><code>
19-
&lt;ul&gt;
20-
&lt;li id="foo"&gt;foo&lt;/li&gt;
21-
&lt;li id="bar"&gt;bar&lt;/li&gt;
22-
&lt;/ul&gt;
23-
</code></pre>
24-
<p>With an index specified, <code>.get(index)</code> retrieves a single element:</p>
25-
<pre><code>console.log( $( "li" ).get( 0 ) );</code></pre>
26-
<p>Since the index is zero-based, the first list item is returned:</p>
27-
<p>
28-
<samp>&lt;li id="foo"&gt;</samp>
29-
</p>
30-
<p>Without a parameter, <code>.get()</code> returns an array of all of the elements:</p>
31-
<pre><code>console.log( $( "li" ).get() );</code></pre>
32-
<p>All of the matched DOM nodes are returned by this call, contained in a standard array:</p>
33-
<p>
34-
<span class="result">[&lt;li id="foo"&gt;, &lt;li id="bar"&gt;]</span>
35-
</p>
4+
<entry type="method" name="get" return="Element">
5+
<title>.get()</title>
6+
<signature>
7+
<added>1.0</added>
8+
<argument name="index" type="Integer">
9+
<desc>A zero-based integer indicating which element to retrieve.</desc>
10+
</argument>
11+
</signature>
12+
<desc>Retrieve one of the DOM elements matched by the jQuery object.</desc>
13+
<longdesc>
14+
<p>The <code>.get()</code> method grants us access to the DOM nodes underlying each jQuery object. Consider a simple unordered list:</p>
15+
<pre><code>
16+
&lt;ul&gt;
17+
&lt;li id="foo"&gt;foo&lt;/li&gt;
18+
&lt;li id="bar"&gt;bar&lt;/li&gt;
19+
&lt;/ul&gt;
20+
</code></pre>
21+
<p>With an index specified, <code>.get(index)</code> retrieves a single element:</p>
22+
<pre><code>console.log( $( "li" ).get( 0 ) );</code></pre>
23+
<p>Since the index is zero-based, the first list item is returned:</p>
24+
<p>
25+
<samp>&lt;li id="foo"&gt;</samp>
26+
</p>
3627

37-
<p>Each jQuery object also masquerades as an array, so we can use the array dereferencing operator to get at the list item instead:</p>
38-
<pre><code>console.log( $( "li" )[0] );</code></pre>
39-
<p>However, this syntax lacks some of the additional capabilities of .get(), such as specifying a negative index:</p>
40-
<pre><code>console.log( $( "li" ).get(-1) );</code></pre>
41-
<p>A negative index is counted from the end of the matched set, so this example returns the last item in the list:</p>
42-
<p>
43-
<samp>&lt;li id="bar"&gt;</samp>
44-
</p>
45-
</longdesc>
46-
<example>
47-
<desc>Select all divs in the document and return the DOM Elements as an Array; then use the built-in reverse() method to reverse that array.</desc>
48-
<code><![CDATA[
49-
function disp(divs) {
50-
var a = [];
51-
for ( var i = 0; i < divs.length; i++) {
52-
a.push( divs[i].innerHTML );
53-
}
54-
$( "span" ).text( a.join(" ") );
55-
}
56-
disp( $( "div" ).get().reverse() );
57-
]]></code>
58-
<css><![CDATA[
59-
span { color:red; }
60-
]]></css>
61-
<html><![CDATA[Reversed - <span></span>
28+
<p>Each jQuery object also masquerades as an array, so we can use the array dereferencing operator to get at the list item instead:</p>
29+
<pre><code>console.log( $( "li" )[0] );</code></pre>
30+
<p>However, this syntax lacks some of the additional capabilities of .get(), such as specifying a negative index:</p>
31+
<pre><code>console.log( $( "li" ).get(-1) );</code></pre>
32+
<p>A negative index is counted from the end of the matched set, so this example returns the last item in the list:</p>
33+
<p>
34+
<samp>&lt;li id="bar"&gt;</samp>
35+
</p>
36+
</longdesc>
37+
<example>
38+
<desc>Display the tag name of the click element.</desc>
39+
<code><![CDATA[
40+
$( "*", document.body).click(function( e ) {
41+
e.stopPropagation();
42+
var domEl = $( this ).get( 0 );
43+
$( "span:first" ).text( "Clicked on - " + domEl.nodeName );
44+
});
45+
]]></code>
46+
<css><![CDATA[
47+
span { color:red; }
48+
div { background:yellow; }
49+
]]></css>
50+
<html><![CDATA[<span>&nbsp;</span>
51+
<p>In this paragraph is an <span>important</span> section</p>
6252
63-
<div>One</div>
64-
<div>Two</div>
65-
<div>Three</div>]]></html>
66-
</example>
67-
<example>
68-
<desc>Display the tag name of the click element.</desc>
69-
<code><![CDATA[
70-
$( "*", document.body).click(function( e ) {
71-
e.stopPropagation();
72-
var domEl = $( this ).get( 0 );
73-
$( "span:first" ).text( "Clicked on - " + domEl.nodeName );
74-
});
75-
]]></code>
76-
<css><![CDATA[
77-
span { color:red; }
78-
div { background:yellow; }
79-
]]></css>
80-
<html><![CDATA[<span>&nbsp;</span>
81-
<p>In this paragraph is an <span>important</span> section</p>
53+
<div><input type="text" /></div>]]></html>
54+
</example>
55+
<category slug="miscellaneous/dom-element-methods"/>
56+
<category slug="version/1.0"/>
57+
</entry>
58+
<entry type="method" name="get" return="Array">
59+
<title>.get()</title>
60+
<signature>
61+
<added>1.0</added>
62+
</signature>
63+
<desc>Retrieve the DOM elements matched by the jQuery object.</desc>
64+
<longdesc>
65+
<p>Consider a simple unordered list:</p>
66+
<pre><code>
67+
&lt;ul&gt;
68+
&lt;li id="foo"&gt;foo&lt;/li&gt;
69+
&lt;li id="bar"&gt;bar&lt;/li&gt;
70+
&lt;/ul&gt;
71+
</code></pre>
72+
<p>Without a parameter, <code>.get()</code> returns an array of all of the elements:</p>
73+
<pre><code>console.log( $( "li" ).get() );</code></pre>
74+
<p>All of the matched DOM nodes are returned by this call, contained in a standard array:</p>
75+
<p>
76+
<span class="result">[&lt;li id="foo"&gt;, &lt;li id="bar"&gt;]</span>
77+
</p>
78+
</longdesc>
79+
<example>
80+
<desc>Select all divs in the document and return the DOM Elements as an Array; then use the built-in reverse() method to reverse that array.</desc>
81+
<code><![CDATA[
82+
function disp(divs) {
83+
var a = [];
84+
for ( var i = 0; i < divs.length; i++) {
85+
a.push( divs[i].innerHTML );
86+
}
87+
$( "span" ).text( a.join(" ") );
88+
}
89+
disp( $( "div" ).get().reverse() );
90+
]]></code>
91+
<css><![CDATA[
92+
span { color:red; }
93+
]]></css>
94+
<html><![CDATA[Reversed - <span></span>
8295
83-
<div><input type="text" /></div>]]></html>
84-
</example>
85-
<category slug="miscellaneous/dom-element-methods"/>
86-
<category slug="version/1.0"/>
87-
</entry>
96+
<div>One</div>
97+
<div>Two</div>
98+
<div>Three</div>]]></html>
99+
</example>
100+
<category slug="miscellaneous/dom-element-methods"/>
101+
<category slug="version/1.0"/>
102+
</entry>
103+
</entries>

0 commit comments

Comments
 (0)