Prevent redirect to other page if first td is click

Hi, how can I prevent to redirect if I click first td on the table

$('#mytable').on('click','tr',function(e){

      window.location = 'tootherpage.php';
});

Thank you in advance.

You are going to want to check if the first td is equal to the table cell that was clicked on:

The first td can be found using:

var firstTd = $('td:first', this).get(0);

And the clicked table cell, can be found using e.target

Hi Paul_Wilkins Thank you it works .

I’ll throw in the sibling CSS selector:

$('#mytable').on('click','td + td',function(e){
1 Like

Yes nice, that’s a more elegant solution for then it is only the specific table cells that get the event, no filtering needed.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.