JSFiddle - React, Tailwind, and code Playground
HTML
<div id="asdf"></div>
<div id="qwer"></div>
JavaScript
(function ( $ ) {
$.fn.test = function() {
var vars = $(this).data('testPlugin');
if (!vars) {
vars = {
x: false,
something: 'else'
};
$(this).data('testPlugin', vars);
}
alert(vars.x);
vars.x = !vars.x;
return this;
};
}( jQuery ));
$('#asdf').test();
$('#qwer').test();
$('#asdf').test();
$('#qwer').test();