How to handle click event in table in first column using jquery?

$('tr').click(function() { $("#showgrid").load('/Products/List/Items/'); }); 

Using this, I handle the click event on a row in a table.

How can I handle only the first column? that is, clicking on the action for only the first column is not for the entire row?

thanks

+4
source share
2 answers

You can handle the first column using the :first-child selector , for example:

 $('tr td:first-child').click(function() { $("#showgrid").load('/Products/List/Items/'); }); 

This selector returns the first <td> in each <tr> .

Alternatively, if you have many lines, use .delegate() for better performance (for only one event handler), for example:

 $('#myTable').delegate('tr td:first-child', 'click', function() { $('#showgrid').load('/Products/List/Items/'); }); 
+4
source

what's easy. just add an event handler to the first td of each tr table. this jQuery code is almost similar to it.

 $("#table tr").find("td:first").click(function() { $("#showgrid").load('/Products/List/Items/'); }); 
+1
source

Source: https://habr.com/ru/post/1308803/


All Articles