I need to know whether I am doing the best way of binding click event through elements in jQuery. I need to avoid duplicate code in my function (since lot of duplicate code is repeated in all functions).
How can I clean this up and do it in a better way?
$(".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+ "");
});