JSFiddle - React, Tailwind, and code Playground

by Ting-Yuan Chang

HTML

<div class="show a">
a
</div>
<div class="show b">
b
</div>
<div class="show c">
c
</div>
<div class="show d">
d
</div>

JavaScript

let list = ['a', 'b', 'c', 'd'];
var handler = function(index) {
  console.log(index, list[index]);
}
for(var key in list ) {
  //$('.show' + '.' + list[key]).unbind('click', handler);
  $('.show' + '.' + list[key]).click(handler.bind(this, key));
}