Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added a .data(obj) example #271

Closed
wants to merge 2 commits into from

3 participants

@Mottie

The documentation was missing this example. So now the code block looks like this:

$('body').data('foo', 52);
$('body').data('bar', { myType: 'test', count: 40 });
$('body').data({ baz: [ 1, 2, 3 ] });

$('body').data('foo'); // 52
$('body').data(); // {foo: 52, bar: { myType: 'test', count: 40 }, baz: [ 1, 2, 3 ] }
entries/data.xml
((5 lines not shown))
$('body').data('foo'); // 52
-$('body').data(); // {foo: 52, bar: { myType: 'test', count: 40 }}
+$('body').data(); // {foo: 52, bar: { myType: 'test', count: 40 }, baz: [ 1, 2, 3 ] }
@gnarf Owner
gnarf added a note

I feel like this should have spaces inside the { and } (see line 27)

Also, we should probably at least update this example to have double quotes to stay with the style guide.

@Mottie
Mottie added a note

Hopefully my update will fix those issues :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@kswedberg
Collaborator

Thanks, @Mottie. I'll merge the pull request asap. In the future, try to make your changes in a topic branch rather than master. See http://contribute.jquery.org/commits-and-pull-requests/ for details.

@kswedberg
Collaborator

Merged in 47b36c9

@kswedberg kswedberg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 26, 2013
  1. @Mottie

    Added .data(obj) example

    Mottie authored
Commits on Mar 27, 2013
  1. @Mottie

    update to match style guide

    Mottie authored
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 4 deletions.
  1. +5 −4 entries/data.xml
View
9 entries/data.xml
@@ -23,11 +23,12 @@
<p>The <code>.data()</code> method allows us to attach data of any type to DOM elements in a way that is safe from circular references and therefore from memory leaks.</p>
<p> We can set several distinct values for a single element and retrieve them later:</p>
<pre><code>
-$('body').data('foo', 52);
-$('body').data('bar', { myType: 'test', count: 40 });
+$("body").data("foo", 52);
+$("body").data("bar", { myType: "test", count: 40 });
+$("body").data({ baz: [ 1, 2, 3 ] });
-$('body').data('foo'); // 52
-$('body').data(); // {foo: 52, bar: { myType: 'test', count: 40 }}
+$("body").data("foo"); // 52
+$("body").data(); // { foo: 52, bar: { myType: "test", count: 40 }, baz: [ 1, 2, 3 ] }
</code></pre>
<p>In jQuery 1.4.3 setting an element's data object with <code>.data(obj)</code> extends the data previously stored with that element. jQuery itself uses the <code>.data()</code> method to save information under the names 'events' and 'handle', and also reserves any data name starting with an underscore ('_') for internal use.</p>
<p>Prior to jQuery 1.4.3 (starting in jQuery 1.4) the .data() method completely replaced all data, instead of just extending the data object. If you are using third-party plugins it may not be advisable to completely replace the element's data object, since plugins may have also set data.</p>
Something went wrong with that request. Please try again.