JSFiddle - React, Tailwind, and code Playground
HTML
<input type="button" id="t1" class="1" value="toggle1">
<span id="t1s"></span>
<input type="button" id="p1" class="1" value="test1" />
<BR />
<input type="button" id="t2" class="2" value="toggle2">
<span id="t2s"></span>
<input type="button" id="p2" class="2" value="test2" />
<BR />
<input type="button" id="t3" class="3" value="toggle3">
<span id="t3s"></span>
<input type="button" id="p3" class="3" value="test3" />
<BR />
JavaScript
var Enabled = new Array();
var DefaultValue = false;
function ToggleState (th)
{
var ind = th.attr('class');
//If isn't in array, add it, default to false
if (!(ind in Enabled))
Enabled[ind] = DefaultValue;
Enabled[ind] = !Enabled[ind]; //Toggle
$('#'+th.attr('id')+'s').text(Enabled[ind]); //Print out in the span
}
function isEnabled (th)
{
var ind = th.attr('class');
if (!(ind in Enabled))
Enabled[ind] = DefaultValue;
return Enabled[ind];
}
//Set click
$(function () {
//Set toggle clicks
$('input[type="button"][id^="t"]').each(function() {
$(this).click(function () {
ToggleState($(this));
});
});
//Set Process
$('input[type="button"][id^="p"]').each(function() {
$(this).click(function () {
if (isEnabled($(this)))
alert('process');
});
});
});