javascriptcanjscanjs-control

CanJS table click event


I am writing an canJS application and so far successful in handling the click event for an html table. Using the following code.

 'table td click':function(el,event){
        console.log('clicked ',el.text());
     }
  1. How to listen to only first column click for the table instead of whole td?
  2. How to retrieve particular column's data from the td (el)?

Solution

  • Try this:

    'table td:nth-child(1) click'
    

    Possible answer of 2nd question, first handle whole tr:

    'table tr:nth-child(1) click':function(el,event){
        console.log(el.find('td').eq(0).html()); // gets first column
     }