Please refer below code
$(".nna-icon-excel").click(function (e) {
var $this = $(this);
$this.parent().attr("href", "?excel=1")
var href = $this.parent().attr("href");
if (activeTab.toLowerCase() == "table") {
action = "expand";
}
else {
action = "expandheatmap";
}
$this.parent().attr("href", href + "&from=" + action + "&expand=" + Expand + "");
});
$(".nna-icon-pdf").click(function (e) {
var $this = $(this);
$this.parent().attr("href", "?savehtml=1&openpdf=1&[email protected]")
var href = $this.parent().attr("href");
if (activeTab.toLowerCase() == "table") {
action = "expand";
}
else {
action = "expandheatmap";
}
$this.parent().attr("href", href + "&from=" + action + "&tabactive=" + action + "&expand=" + Expand + "");
});
$(".gridoptions-anchor").click(function (e) {
var $this = $(this);
$this.attr("href", "/home/xx/Index" + "/?columnchooser=1");
var href = $(this).attr("href");
var action = "";
if (activeTab.toLowerCase() == "table") {
action = "expand";
}
else {
action = "expandheatmap";
}
$this.attr("href", href + "&from=" +action + "&expand=" + Expand+ "");
});
I need to know whether I am doing the best way of binding click event through element in jQuery. I need to avoid duplicate codes in my function (since lot of duplicate codes repeated in all functions).
How to clean the above code and do it in a better way ?