JSFiddle - React, Tailwind, and code Playground
by jonva
HTML
<div class="container">
<button data-target='foo'>foo</button>
<button data-target='bar'>bar</button>
</div>
JavaScript
(function($){
this.foo = 'foo_value';
this.bar = 'bar_value';
var self = this;
function getVar(theVar){
console.log(self[foo]);
console.log(self[bar]);
//the code...
}
this.foo_value = "some random string";
this.bar_value = "some random string";
$('.container').on('click', 'button', function(){
getVar(this.dataset.target);
})
}(jQuery))