I have a table and I want to click on the line TR to read its class and populate fields into editing the value of this line, that is, now I cannot determine the class by hover and read the value attributes from it.

<tbody align="center" style="background: #fff; height" 25px;" class="d_table"> <tr class="14"> <td id="d_table_name">1</td> <td id="d_table_family">2</td> <td id="d_table_kolvo">3</td> <td id="d_table_razmer">4</td> <td id="d_table_stats" style="background-color: #f2f2f2;">5</td> <td id="d_table_aaa">6</td> </tr> <tr class="15"> <td id="d_table_name">1</td> <td id="d_table_family">2</td> <td id="d_table_kolvo">3</td> <td id="d_table_razmer">4</td> <td id="d_table_stats" style="background-color: #f2f2f2;">5</td> <td id="d_table_aaa">6</td> </tr> <tr class="16"> <td> 111... </td> <td> 2... </td> <td> 3... </td> <td> 4... </td> <td> 5... </td> <td> 6... </td> </tr> </tbody> 
  • So, I assigned the same class to all TRs and hung on it with click $ ('. Line_event'). Click (function () now I can’t figure out how to do what to count from TD - I’m like an ID, but I don’t count, tell me why can't do it like this? var name = $ ("# d_table_name"). val (); alert ('line_event' + name); - oldzas

1 answer 1

Two major mistakes:

  1. id is a unique identifier and should not be repeated. Use attributes.
  2. val () works for input, use .html () to get the contents of a cell

In general, here is a working example: http://jsfiddle.net/SLonoed/UahPM/

  • Corrected a link to the answer. - Dmitry Manannikov