Skip to content

Commit 34b6d52

Browse files
committed
data: Explicitly disavow writing data-* attributes
Fixes jquerygh-1023
1 parent 85ca764 commit 34b6d52

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

entries/data.xml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ $( "body" ).data( { baz: [ 1, 2, 3 ] } );
2929
$( "body" ).data( "foo" ); // 52
3030
$( "body" ).data(); // { foo: 52, bar: { isManual: true }, baz: [ 1, 2, 3 ] }
3131
</code></pre>
32+
<p>Using the <code>data()</code> method to update data does not affect attributes in the DOM. To set a data-* attribute value, use <code><a href="/attr/">attr</a></code>.</p>
3233
<p>Prior to jQuery 1.4.3, <code>.data( obj )</code> completely replaced all data. Since jQuery 1.4.3, data is instead extended by shallow merge.</p>
3334
<p>Since <strong>jQuery 3</strong>, every two-character sequence of "-" (U+002D) followed by a lowercase ASCII letter in a key is replaced by the uppercase version of the letter, in alignment with the <a href="https://html.spec.whatwg.org/multipage/dom.html#dom-dataset">HTML dataset API</a>. A statement like <code>$( "body" ).data( { "my-name": "aValue" } ).data();</code> will return <code>{ myName: "aValue" }</code>.</p>
3435
<p>Due to the way browsers interact with plugins and external code, the <code>.data()</code> method cannot be used on <code>&lt;object&gt;</code> (unless it's a Flash plugin), <code>&lt;applet&gt;</code> or <code>&lt;embed&gt;</code> elements.</p>

0 commit comments

Comments
 (0)