Select the id of all products and for each of them create a line of the following type "id.doc", for example "1.doc". Add for each selected href element "<a>" with class "document" which should result for example <a href = "1.doc"> 1 </a> <a href="2.doc"> 2 </a>

<html> <table id='orders' border='1'> <thead> <tr> <th>id</th> <th>Товар</th> <th>Цена</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>AAA</td> <td>30p</td> </tr> <tr> <td>2</td> <td>BBB</td> <td>50p</td> </tr> <tr> <td>3</td> <td>CCC</td> <td>50p</td> </tr> </tbody> </table> </html> <script> $(document).ready(function() { $("td:first-child").before('<a href="#"></a>'); //туть нужно исправить }); </script> 
  • I didn't understand the task at all, you wrote such a mess ... - PhoEn-X
  • select the id column and make this element a link for example <a href="1.doc"> 1 </a> <a href="2.doc"> 2 </a> and so on - cheburashkarf
  • @cheburashkarf, if the correct answer is given, check the box to the left of the answer. - PhoEn-X

1 answer 1

 <script type="text/javascript"> $(document).ready(function() { $("#orders tbody tr").each(function() { var link = "http://site.ru/" + $(this).children('td').eq(0).text() + ".doc"; var text = $(this).children('td').eq(0).html(); $(this).children('td').eq(0).html("<a href=\"" + link + "\">" + text + "</a>"); }); }); </script> 
  • . $ (this) .children ('td'). eq (0) .html ("<a href=\" + link + "\">" + text + "</a>"); => $ (this) .children ('td'). eq (0) .html ($ ('<a>', {'href': link, 'html': text})); - etki