Abhay Singh
Abhay Singh

Reputation: 437

How to get table row specific column to be clicked using javascript?

I have given row a class name , and i want to set a click function to be clicked on specific column of that row.

Here is the code-

var row = $('<tr class="parent_row"><td>' + '</td>' + '<td>' + data1 + '</td>' + '<td>' 
+  data2  + '</td>; + '<td>' + data3 + "</td></tr>"

My click functon-

$('.parent_row).find("td:eq(1)").(click(function(e) { })

This is not working, I want that second column of row that is 'data1' should be clicked. I need help?

Upvotes: 0

Views: 417

Answers (2)

Madhav Palshikar
Madhav Palshikar

Reputation: 312

You should write click event on td.

$('tr.parent_row td:eq(1)').on('click', function(){
    // handle it here $(this)
});

Upvotes: 0

Armedin Kuka
Armedin Kuka

Reputation: 675

You can rewrite like this :

$('.parent_row').find("td:eq(1)").on("click",function(e){
  //your stuff
})

I tried it out and it worked for me in this way.

Upvotes: 1

Related Questions