Skip to content

Commit 9b988ff

Browse files
committed
.get(): Split into 2 signatures and update content.
1 parent 3142c44 commit 9b988ff

1 file changed

Lines changed: 26 additions & 22 deletions

File tree

entries/get.xml

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,55 @@
55
<title>.get()</title>
66
<signature>
77
<added>1.0</added>
8-
<argument name="index" type="Number" optional="true">
8+
<argument name="index" type="Integer">
99
<desc>A zero-based integer indicating which element to retrieve.</desc>
1010
</argument>
1111
</signature>
12+
<signature>
13+
<added>1.0</added>
14+
</signature>
1215
<desc>Retrieve the DOM elements matched by the jQuery object.</desc>
1316
<longdesc>
14-
<p>The <code>.get()</code> method grants us access to the DOM nodes underlying each jQuery object. Suppose we had a simple unordered list on the page:</p>
17+
<p>The <code>.get()</code> method grants us access to the DOM nodes underlying each jQuery object. Consider a simple unordered list:</p>
1518
<pre><code>
1619
&lt;ul&gt;
1720
&lt;li id="foo"&gt;foo&lt;/li&gt;
1821
&lt;li id="bar"&gt;bar&lt;/li&gt;
1922
&lt;/ul&gt;
2023
</code></pre>
21-
<p>Without a parameter, <code>.get()</code> returns all of the elements:</p>
22-
<pre><code>alert($('li').get());</code></pre>
23-
<p>All of the matched DOM nodes are returned by this call, contained in a standard array:</p>
24-
<p>
25-
<span class="result">[&lt;li id="foo"&gt;, &lt;li id="bar"&gt;]</span>
26-
</p>
27-
<p>With an index specified, .get() will retrieve a single element:</p>
28-
<pre><code>($('li').get(0));</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>
2926
<p>Since the index is zero-based, the first list item is returned:</p>
3027
<p>
3128
<samp>&lt;li id="foo"&gt;</samp>
3229
</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>
36+
3337
<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>
34-
<pre><code>alert($('li')[0]);</code></pre>
38+
<pre><code>console.log( $( "li" )[0] );</code></pre>
3539
<p>However, this syntax lacks some of the additional capabilities of .get(), such as specifying a negative index:</p>
36-
<pre><code>alert($('li').get(-1));</code></pre>
37-
<p>A negative index is counted from the end of the matched set, so this example will return the last item in the list:</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>
3842
<p>
3943
<samp>&lt;li id="bar"&gt;</samp>
4044
</p>
4145
</longdesc>
4246
<example>
43-
<desc>Selects all divs in the document and returns the DOM Elements as an Array, then uses the built-in reverse-method to reverse that array.</desc>
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>
4448
<code><![CDATA[
4549
function disp(divs) {
4650
var a = [];
47-
for (var i = 0; i < divs.length; i++) {
48-
a.push(divs[i].innerHTML);
51+
for ( var i = 0; i < divs.length; i++) {
52+
a.push( divs[i].innerHTML );
4953
}
50-
$("span").text(a.join(" "));
54+
$( "span" ).text( a.join(" ") );
5155
}
52-
disp( $("div").get().reverse() );
56+
disp( $( "div" ).get().reverse() );
5357
]]></code>
5458
<css><![CDATA[
5559
span { color:red; }
@@ -61,12 +65,12 @@ disp( $("div").get().reverse() );
6165
<div>Three</div>]]></html>
6266
</example>
6367
<example>
64-
<desc>Gives the tag name of the element clicked on.</desc>
68+
<desc>Display the tag name of the click element.</desc>
6569
<code><![CDATA[
66-
$("*", document.body).click(function (e) {
70+
$( "*", document.body).click(function( e ) {
6771
e.stopPropagation();
68-
var domEl = $(this).get(0);
69-
$("span:first").text("Clicked on - " + domEl.tagName);
72+
var domEl = $( this ).get( 0 );
73+
$( "span:first" ).text( "Clicked on - " + domEl.nodeName );
7074
});
7175
]]></code>
7276
<css><![CDATA[

0 commit comments

Comments
 (0)