Checking if the clicked column is the first in the row or not
it took JQuery code to check if the clicked column is the first in the row or not.
A table is used to select certain parameters. And onclick, the background of the clicked td is shown (check the box) by assigning a CSS class with jquery and removing that class from all td elements (sbling td) (one selection for each row).
The problem is that it shouldn't do this when clicking on the first column as it contains the shortcuts for the option / question.
the current code looks like this:
$(document).ready(function () {
$("table tr td").click(function () {
$(this).parent().find('td').each(function () {
$(this).removeClass("CheckMark");
});
$(this).addClass("CheckMark");
});
});
If the column is the first, no action should be taken as it contains the Labels for parameter.
I hope the situation is adequate :).
Regards, A.Ali
source to share
Use index () to find out the first column when clicked td
. If index () gives zero, then it will be the first column as it index()
gives a zero-based index.
$(document).ready(function () {
$("table tr td").click(function () {
if($(this).index() == 0) return;
$(this).parent().find('td').each(function () {
$(this).removeClass("CheckMark");
});
$(this).addClass("CheckMark");
});
});
source to share