'Jquery - Hyperlink cannot be click
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.
Solution 1:[1]
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');
});
Solution 2:[2]
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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nikes |
| Solution 2 | Aman Kumar Sharma |
