JSFiddle - React, Tailwind, and code Playground

by shapeshifta

HTML

<div id="test" data-info="Hi, ich bin der Text aus dem data Attribut :)" data-config='{ "intro": false, "foo": "Alles klar?"}'>
Ich bin nur ein div und steh hier rum
</div>
<div id="test2" data-info="Hi, ich bin der Text aus dem data Attribut :)" data-config="{ 'intro': false, 'foo': 'Alles klar?'}">
Ich bin nur ein div und steh hier rum
</div>

JavaScript

//data-config mit json notation
var test = $('#test');
test.html( test.data('info') + test.data('config').foo);
console.log(typeof test.data('config'));

//data-config nicht json konform
var test2 = $('#test2');
test2.html( test2.data('info') + test2.data('config').foo);
console.log(typeof test2.data('config'));

//pures JS
var elms = document.querySelectorAll('#test, #test2');
console.log( elms[0].dataset.info, elms[1].dataset.config);