Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refer to .map() in jQuery.map() entry and vice versa.

Fixes #46.
  • Loading branch information...
commit 90dc60066be70f1c31340950a1ba236711c64dd6 1 parent 26f642c
@kswedberg kswedberg authored
Showing with 7 additions and 5 deletions.
  1. +2 −1  entries/jQuery.map.xml
  2. +5 −4 entries/map.xml
View
3  entries/jQuery.map.xml
@@ -21,6 +21,7 @@
</signature>
<desc>Translate all items in an array or object to new array of items.</desc>
<longdesc>
+ <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>
<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>
<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>
<pre>
@@ -138,4 +139,4 @@ array = $.map(array, function(a, index) {
<category slug="utilities"/>
<category slug="version/1.0"/>
<category slug="version/1.6"/>
-</entry>
+</entry>
View
9 entries/map.xml
@@ -9,7 +9,8 @@
</signature>
<desc>Pass each element in the current matched set through a function, producing a new jQuery object containing the return values.</desc>
<longdesc>
- <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>
+ <p>If you wish to process a plain array or object, use the <a href="/jQuery.map/">jQuery.map()</a> instead. </p>
+ <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>
<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>
<pre><code>
&lt;form method="post" action=""&gt;
@@ -33,10 +34,10 @@
&lt;/fieldset&gt;
&lt;/form&gt;
</code></pre>
- <p>We can get a comma-separated list of checkbox <code>ID</code>s:</p>
+ <p>To get a comma-separated list of checkbox <code>ID</code>s:</p>
<pre><code>$(':checkbox').map(function() {
return this.id;
- }).get().join(',');</code></pre>
+ }).get().join();</code></pre>
<p>The result of this call is the string, <code>"two,four,six,eight"</code>.</p>
<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>
</longdesc>
@@ -133,4 +134,4 @@ input { clear:left}
</example>
<category slug="traversing/filtering"/>
<category slug="version/1.2"/>
-</entry>
+</entry>
Please sign in to comment.
Something went wrong with that request. Please try again.