There is a table:

<h4 class="text-center">Матрица A</h4> <table class="matrixA"> <tr> <td><input type="text"></td> <td><input type="text"></td> </tr> <tr> <td><input type="text"></td> <td><input type="text"></td> </tr> </table> 

It is necessary to fill the place holders of the cells with their corresponding coordinates (ie, a1,1, a1,2, etc.). How to implement it?

Link to codepen: http://codepen.io/ivan1fun/pen/dMZZYG

  • use the index () method from tr and td as an option. - Jean-Claude
  • Maybe this is not the answer, but just in case matrixcalc.org considers matrices, you can look at the sources, they are not compressed there - Vasily Barbashev
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

 $("input").each(function () { var $this = $(this); $this.attr("placeholder", "a[" + $this.closest("td").index() + ", " + $this.closest("tr").index() + "]"); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <caption>Матрица A</caption> <tr> <td><input type="text"></td> <td><input type="text"></td> <td><input type="text"></td> </tr> <tr> <td><input type="text"></td> <td><input type="text"></td> <td><input type="text"></td> </tr> <tr> <td><input type="text"></td> <td><input type="text"></td> <td><input type="text"></td> </tr> </table> 

  • Many thanks! What you need :) - Ivan Berestov