简体   繁体   中英

How to update value of cell of specific row when iterating with each

I am getting the values of the first column of a table and based on an if statement I need to update the value of the third column of each specific row. This is what I do:

$("#attributes_tbl tr").each(function(){
  var value = $(this).find("td input:nth-child(2)").val();
  if (value in attribute_enumerations){
    description = attribute_enumerations[value]
    console.log(description)
    $('td:nth-child(3) input').val(description);
  }
});

The above snippet updates all the rows of the third column. What I need is to update the cell of the third column of the current row:

// I need this to update only the specific cell of the current row (from the "each" loop)

$('td:nth-child(3) input').val(description);

How can I specify this in jQuery?

To affect only the current row, change:

$('td:nth-child(3) input').val(description);

To:

$(this).find('td:nth-child(3) input').val(description);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM