JSFiddle - React, Tailwind, and code Playground

by Marc-André Lafortune

HTML

<pre id="x"/>

JavaScript

$x = $('#x')
$x.data()
$x.attr('data-foo', 42)
$x.append("Because of initial call the data(), this is undefined: " + $x.data().foo + "\n")
$x.data('foo') // Since value of foo is undefined, this will check for a data-foo attribute
$x.append("But asking for 'foo' directly will use the attribute,\nso subsequent calls have that value: " + $x.data().foo + "\n")
$x.attr('data-foo', 666)
$x.append("Once initialized, the value won't be updated: " + $x.data().foo + "\n")