Jquery- Get the value of first td in table

后端 未结 6 2425
旧巷少年郎
旧巷少年郎 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:27

    If you need to get all td's inside tr without defining id for them, you can use the code below :

    var items = new Array();
    
    $('#TABLE_ID td:nth-child(1)').each(function () {
          items.push($(this).html());
    });
    

    The code above will add all first cells inside the Table into an Array variable.

    you can change nth-child(1) which means the first cell to any cell number you need.

    hope this code helps you.

提交回复
热议问题