I have table, then table row can be clicked. But some cell, cannot be clicked if there is a hyperlinks. Because if i allow it, there will be 2 action. Action on tr click and action on hyperlink click.
so i decide to disable thats cell.
$("tbody").on("click", "tr td:last-child", function() {
return false;
});
But when i do this,, my hyperlink cannot be clicked.
This is my full script
$("tbody").on("click", "tr td:last-child", function() {
return false;
});
$("tbody").on("click", "tr td:nth-last-child(2)", function() {
return false;
});
$("tbody").on("click", "tr", function() {
console.log('tr click');
});
https://jsfiddle.net/1twzdm9c/18/
In my version, i cant click tr and hyperlink,, but in jsfiddle, im still can click tr but hyperlink cannot wont effect.
CodePudding user response:
Just not bind the click in first place
$("tbody").find("tr td").not(":last,:nth-last-child(2)").on("click", function() {
console.log('tr click');
});
https://jsfiddle.net/27jygkqx/
CodePudding user response:
add this attribute in non clickable td
<td data-click="false">....
<td data-click="false">...
<script>
$("tbody").on("click", "tr td:not([data-click='false'])", function() {
console.log('tr click');
});
</script>