JSFiddle - React, Tailwind, and code Playground
HTML
<div id="div1"></div>
<div id="div2"></div>
JavaScript
(function($) {
$.fn.test = function() {
return this.each(function() {
var x = false;
alert(x);
if (!x) {
x = true;
}
});
}
}(jQuery));
$("#div1").test(); //false
$("#div2").test(); // false