0

I have a table with entries and each row of the table is clickable (when you click the row, it goes to a details page). Everything is ok except the fact that if I put an anchor on the same row, it will try to go to anchor's URL and immediately after it will redirect to the row's attached link.

How can I prevent the row action using jQuery?

<tr class="clickable-row" ...>
    <td><a href="..."></a></td>
</tr>

$('.clickable-row').click(function () {
        document.location = "...";
});
tzortzik
  • 4,993
  • 9
  • 57
  • 88

2 Answers2

3

use stopPropagation(); to stop the default action

$("a").click(function(e){

e.stopPropagation();

// do ur work
});

Description: Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.

Balachandran
  • 9,567
  • 1
  • 16
  • 26
0

You Can try this if this is according to your requirements.

<a href="#" onclick="myJsFunc();">Run JavaScript Code</a>

for more details: Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?

Community
  • 1
  • 1
Dheer
  • 773
  • 1
  • 6
  • 16