JSFiddle - React, Tailwind, and code Playground
by dwaddell
HTML
<script src="http://code.jquery.com/jquery-1.6.2.js"></script>
JavaScript
outElement = $('pre');
body = $('body');
function outIt(label, out) {
outElement.append('<h2>' + label + '</h2>');
switch (typeof out) {
case 'undefined':
outElement.append('<undefined>' + "\n");
break;
case 'string':
outElement.append(out + "\n");
break;
default:
var didOut = false
$.each(out, function(key, value) {
didOut = true;
outElement.append(key + ': ' + value + "\n");
});
if (!didOut) {
outElement.append("<empty>\n");
}
break;
}
outElement.append("\n");
}
outIt('Original .data()', body.data());
body.data({
"camelBar": "camel",
"hyphen-foo": "hyphen"
});
outIt('.data() after adding via object with hyphenated key', body.data());
$.each(['camel-bar', 'camelBar', 'hyphen-foo', 'hyphenFoo'], function(i, k) {
outIt('Accessing ' + k, body.data(k));
});