Try this way:
Markup
<a href="javascript:void(0);" onclick="fnShowHide.call(this, [1]);" id="name">Show Name</a>
JS
function fnShowHide( iCol ) {
//Your code
$(this).text(function(_, text) { //now this refers to the element clicked
return text === 'Show Name' ? 'Hide Name' : 'Show Name';
});
}
Fiddle
or use jquery for event registration and get rid of inline onclick attribute on the element, use data-* attribute to specify the relative data for the element and use jquery data api to get it :
Makup
<a href="javascript:void(0);" data-icol="[1]" id="name">Show Name</a>
JS
$(function(){
$('#name').click(fnShowHide);
});
function fnShowHide()
{
var iCol = $(this).data('icol'); //will give [1]
//Your code
$(this).text(function(_, text) { //now this refers to the element clicked
return text === 'Show Name' ? 'Hide Name' : 'Show Name';
});
}
Demo
Update
Based on the comment support for multiple fields.
$(function () {
$('.fields').click(fnShowHide);
});
var showregex = /^Show/i; //matches starting Show word
var hideregex = /^Hide/i; //matches starting Hide word
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) ? //test if it Show
text.replace(showregex, 'Hide') : //replace it with hide
text.replace(hideregex, 'Show'); // else replace it with show
});
}
Fiddle