From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- files/pl/web/api/htmlelement/dataset/index.html | 134 ++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 files/pl/web/api/htmlelement/dataset/index.html (limited to 'files/pl/web/api/htmlelement/dataset') diff --git a/files/pl/web/api/htmlelement/dataset/index.html b/files/pl/web/api/htmlelement/dataset/index.html new file mode 100644 index 0000000000..fac7ec119f --- /dev/null +++ b/files/pl/web/api/htmlelement/dataset/index.html @@ -0,0 +1,134 @@ +--- +title: HTMLElement.dataset +slug: Web/API/HTMLElement/dataset +translation_of: Web/API/HTMLOrForeignElement/dataset +--- +
{{ APIRef("HTML DOM") }}
+ +

Właściwość dataset interfejsu {{domxref("HTMLElement")}} pozwala na odczyt/zapis niestandardowcyh atrybutów (data-*) elementu. Dostęp ten jest możliwy w HTMLu jak i w DOMie.  It is a map of DOMString, one entry for each custom data attribute. Zauważ że właściwość dataset można odczytać, ale nie zmieniać bezpośrednio. Zamiast tego, wszystkie zapisy muszą być wykonywane na pojedynczych polach dataset, które odpowiadają atrybutom danych. Note also that an HTML data-attribute and its corresponding DOM dataset.property do not share the same name, but they are always similar:

+ + + +

In addition to the information below, you'll find a how-to guide for using HTML data attributes in our article Using data attributes.

+ +

Zmiana nazw

+ +

dash-style to camelCase: A custom data attribute name is transformed to a key for the {{ domxref("DOMStringMap") }} entry with the following rules

+ + + +

camelCase to dash-style: The opposite transformation, that maps a key to an attribute name, uses the following rules:

+ + + +

The restriction in the rules above ensures that the two transformations are the inverse one of the other.

+ +

For example, the attribute named data-abc-def corresponds to the key abcDef.

+ + + +

Dostęp do wartości

+ + + + + +

Ustawianie wartości

+ + + +

Składnia

+ + + +

Przykłady

+ +
<div id="user" data-id="1234567890" data-user="johndoe" data-date-of-birth>John Doe</div>
+ +
const el = document.querySelector('#user');
+
+// el.id == 'user'
+// el.dataset.id === '1234567890'
+// el.dataset.user === 'johndoe'
+// el.dataset.dateOfBirth === ''
+
+// set the data attribute
+el.dataset.dateOfBirth = '1960-10-03';
+// Result: el.dataset.dateOfBirth === 1960-10-03
+
+delete el.dataset.dateOfBirth;
+// Result: el.dataset.dateOfBirth === undefined
+
+// 'someDataAttr' in el.dataset === false
+el.dataset.someDataAttr = 'mydata';
+// Result: 'someDataAttr' in el.dataset === true
+
+ +

Specyfikacje

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecyfikacjaStatusKomentarz
{{SpecName('HTML WHATWG', "dom.html#dom-dataset", "HTMLElement.dataset")}}{{Spec2('HTML WHATWG')}}No change from latest snapshot, {{SpecName('HTML5.1')}}
{{SpecName('HTML5.1', "dom.html#dom-dataset", "HTMLElement.dataset")}}{{Spec2('HTML5.1')}}Snapshot of {{SpecName('HTML WHATWG')}}, no change from {{SpecName('HTML5 W3C')}}
{{SpecName('HTML5 W3C', "dom.html#dom-dataset", "HTMLElement.dataset")}}{{Spec2('HTML5 W3C')}}Snapshot of  {{SpecName('HTML WHATWG')}}, initial definition.
+ +

Browser compatibility

+ + + +

{{Compat("api.HTMLElement.dataset")}}

+ +

Zobacz także

+ + -- cgit v1.2.3-54-g00ecf