pheromix
pheromix

Reputation: 19287

How to get the clicked cell inside the click event handler of a table row?

There is a html table populated dynamically from an ajax , on which there is a click handler on the tr element :

$("#table").on("click" ,"tr", function() {
   // working codes
}

I want to get the corresponding clicked cell inside the above code. How to do that ?

Upvotes: 0

Views: 123

Answers (1)

Barmar
Barmar

Reputation: 780724

Delegate to td instead of tr. Then this will be the clicked cell.

$("#table").on("click" ,"td", function() {
   console.log($(this).text());
}

Upvotes: 1

Related Questions