Jquery- Get the value of first td in table

后端 未结 6 2403
旧巷少年郎
旧巷少年郎 2020-12-03 02:51

I am trying to get the value of first td in each tr when a users clicks \"click\".

The result below will output aa ,ee or ii. I was thinking about using closest(\'t

6条回答
  •  北海茫月
    2020-12-03 03:20

    $(".hit").click(function(){
       var values = [];
       var table = $(this).closest("table");
       table.find("tr").each(function() {
          values.push($(this).find("td:first").html());
       });
    
       alert(values);    
    });
    

    You should avoid $(".hit") it's really inefficient. Try using event delegation instead.

提交回复
热议问题