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

Using this I am handling click event on the row of the table.

How can I handle only on the first column? that is, giving click action to only first column not on entire row?

thanks

2 Answers 2

4

You can handle the first column using :first-child selector, like this:

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

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

Alternatively, if you have a lot of rows, use .delegate() for better performance (only one event handler), like this:

$('#myTable').delegate('tr td:first-child', 'click', function() {
  $('#showgrid').load('/Products/List/Items/');
});
Sign up to request clarification or add additional context in comments.

2 Comments

@Hunter - I've explicitly specified td in the selector, it'll select each td that is also a first-child of it's parent.
I need to get the first-child value? with that that click?
1

that is simple. just add an event handler to the first td of each tr of the table. this jQuery code is almost like speaking it.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.