<h1>Duplicate/double attributes, data-attributes, and attribute values</h1>
<p>
Several experiments with setting duplicate attributes on html elements,<br>
and getting their values in javascript in different ways.
</p>
<hr>
<h2>Tip: See console for output.</h2>
<hr>
<h2>Duplicate/double attributes</h2>
<p>
Double attributes get lost, and only the first value is used.<br>
Tested with: obj.attributes, obj.getAttribute(), obj.dataset and $(obj).data().<br>
E.G.: <code><x bbb="1" bbb="2"> ⇒</code> will only use value "1".<br>
</p>
<hr>
<h2>Accessing attribute values, using different kind of access methods and keys, and getting different kinds of values:</h2>
<code><x data-abc-def="1"></code><br>
<ul>
<li>
<code>element.attributes['data-abc-def'].value ⇒ stringvalue</code>:<br>
Use keys exactly as they appear in html source.<br>
Values are always returned as strings.<br>
<li>
<code>element.getAttribute('data-abc-def') ⇒ stringvalue</code>:<br>
Use keys exactly as they appear in html source.<br>
Values are always returned as strings.<br>
<li>
<code>element.dataset['abc-def'] ⇒ stringvalue</code>:<br>
<code>'data-'</code> stripped from html source attributename.<br>
Dashed keys are converted to camelCase.<br>
Values are always returned as strings.<br>
<li>
<code>$(element).data()['abcDef'] ⇒ convertedvalue</code>:<br>
<code>'data-'</code> stripped from html source attributename.<br>
Dashed keys are converted to camelCase.<br>
Values are converted to their respective type and value:<br>
null, false, true, numbers, floats, JSONstrings to object.<br>
</ul>
<hr>
<h2>Elements as used in JS examples:</h2>
<div>
<code>
<x aaa bbb="2" bbb="3"
data-xxx="1" data-xxx="2"
data-abc-def_ghi="jkl">
</code> :
<br>
<x aaa bbb="2" bbb="3"
data-xxx="1" data-xxx="2"
data-abc-def_ghi="jkl">x</x>
<br>
<code>
<input type="text" value="x" value="y">
</code>
<br>
<input...