JSFiddle - React, Tailwind, and code Playground
HTML
<a href="javascript:void(0);" data-icol="[1]" class="fields" id="name">Show Name</a>
<a href="javascript:void(0);" data-icol="[2]" class="fields" id="address">Show Address</a>
<a href="javascript:void(0);" data-icol="[3]" class="fields" id="company">Show Company</a>
JavaScript
$(function () {
$('.fields').click(fnShowHide);
});
var showregex = /^Show/i;
var hideregex = /^Hide/i;
function fnShowHide() {
var iCol = $(this).data('icol'); //will give [1]
console.log(iCol);
//Your code
$(this).text(function (_, text) { //now this refers to the element clicked
return showregex.test(text) ? text.replace(showregex, 'Hide') : text.replace(hideregex, 'Show');
});
}