Skip to content

Commit 90dc600

Browse files
committed
Refer to .map() in jQuery.map() entry and vice versa.
Fixes #46.
1 parent 26f642c commit 90dc600

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

entries/jQuery.map.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
</signature>
2222
<desc>Translate all items in an array or object to new array of items.</desc>
2323
<longdesc>
24+
<p>If you wish to process a jQuery object — for example, <code>$('div').map( callback );</code> — use <a href="/jQuery.map/">.map()</a> instead. </p>
2425
<p>The <code>$.map()</code> method applies a function to each item in an array or object and maps the results into a new array. <strong>Prior to jQuery 1.6</strong>, <code>$.map()</code> supports traversing <em>arrays only</em>. <strong>As of jQuery 1.6</strong> it also traverses objects.</p>
2526
<p>Array-like objects &#x2014; those with a <code>.length</code> property <em>and</em> a value on the <code>.length - 1</code> index &#x2014; must be converted to actual arrays before being passed to <code>$.map()</code>. The jQuery library provides <a href="http://api.jquery.com/jQuery.makeArray/">$.makeArray()</a> for such conversions.</p>
2627
<pre>
@@ -138,4 +139,4 @@ array = $.map(array, function(a, index) {
138139
<category slug="utilities"/>
139140
<category slug="version/1.0"/>
140141
<category slug="version/1.6"/>
141-
</entry>
142+
</entry>

entries/map.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
</signature>
1010
<desc>Pass each element in the current matched set through a function, producing a new jQuery object containing the return values.</desc>
1111
<longdesc>
12-
<p>As the return value is a jQuery-wrapped array, it's very common to <code>get()</code> the returned object to work with a basic array.</p>
12+
<p>If you wish to process a plain array or object, use the <a href="/jQuery.map/">jQuery.map()</a> instead. </p>
13+
<p>As the return value is a jQuery object, which contains an array, it's very common to call <code>.get()</code> on the result to work with a basic array.</p>
1314
<p>The <code>.map()</code> method is particularly useful for getting or setting the value of a collection of elements. Consider a form with a set of checkboxes in it:</p>
1415
<pre><code>
1516
&lt;form method="post" action=""&gt;
@@ -33,10 +34,10 @@
3334
&lt;/fieldset&gt;
3435
&lt;/form&gt;
3536
</code></pre>
36-
<p>We can get a comma-separated list of checkbox <code>ID</code>s:</p>
37+
<p>To get a comma-separated list of checkbox <code>ID</code>s:</p>
3738
<pre><code>$(':checkbox').map(function() {
3839
return this.id;
39-
}).get().join(',');</code></pre>
40+
}).get().join();</code></pre>
4041
<p>The result of this call is the string, <code>"two,four,six,eight"</code>.</p>
4142
<p>Within the callback function, <code>this</code> refers to the current DOM element for each iteration. The function can return an individual data item or an array of data items to be inserted into the resulting set. If an array is returned, the elements inside the array are inserted into the set. If the function returns <code>null</code> or <code>undefined</code>, no element will be inserted.</p>
4243
</longdesc>
@@ -133,4 +134,4 @@ input { clear:left}
133134
</example>
134135
<category slug="traversing/filtering"/>
135136
<category slug="version/1.2"/>
136-
</entry>
137+
</entry>

0 commit comments

Comments
 (0)