Reputation: 4067
I am using an html grid.I want to make all the the cells of gridview clickable except for the cells in the first column.How can i make it possible with jQuery?
This is the code i have written for making all the cells in the gridview clickable
$("#gdTable tr:has(td)").click(function (e) {
selTD = $(e.target).closest("td");
selTR = $(e.target).closest("td").parent();;
if (selTD.hasClass("selected")) selTD.removeClass("selected");
else {
selTR.children().removeClass("selected");
selTD.addClass("selected");
}
getCellValue();
});
Upvotes: 1
Views: 851
Reputation: 148120
Try using :not along with :first-child or :nth-child
$("#gdTable td:not(:first-child)").click(function (e) {
selTD = $(e.target).closest("td");
selTR = $(e.target).closest("td").parent();;
if (selTD.hasClass("selected")) selTD.removeClass("selected");
else {
selTR.children().removeClass("selected");
selTD.addClass("selected");
}
getCellValue();
});
Upvotes: 1
Reputation: 74738
You can try changing just your selector this way:
$("#gdTable tr:has(td)").each(function () {
$("td:not(:first)", this).click(function (e) {
selTD = $(e.target).closest("td");
selTR = $(e.target).closest("td").parent();;
if (selTD.hasClass("selected")) {
selTD.removeClass("selected");
} else {
selTR.children().removeClass("selected");
selTD.addClass("selected");
}
getCellValue();
});
});
Upvotes: 0