There are several blocks of the same type:
<div class="b-matrix b-matrix_border"> <span class="result"></span> <table class="b-matrix__table b-matrix__table_border"> <tr> <td><input class="matrix-cell" type="text" placeholder="c1,1" value="" disabled /></td> <td><input class="matrix-cell" type="text" placeholder="c1,2" value="" disabled /></td> </tr> <tr> <td><input class="matrix-cell" type="text" placeholder="c2,1" value="" disabled /></td> <td><input class="matrix-cell" type="text" placeholder="c2,2" value="" disabled /></td> </tr> </table> </div> <div class="b-matrix b-matrix_border"> <span class="matrix-name-A">A</span> <table class="b-matrix__table b-matrix__table_border"> <tr> <td><input class="matrix-cell" type="text" placeholder="a1,1" value="" /></td> <td><input class="matrix-cell" type="text" placeholder="a1,2" value="" /></td> </tr> </table> </div> Task: if in a block with a class .b-matrix there is a child span with a class .result (or with another class), then the input tags in the table of this particular block should be set to placeholder - this.tableBox.input.setAttribute('placeholder', 'c ' + i + ',' + j); There are several blocks, respectively, there should be a condition - If there is a span with the class result, then we get a 1.1 a2,2, etc., and if the class of the span is different, then b 1,1 b 1,2 and so on .
I think it should be something like this:
(function setPlaceholder() { var tableBox = document.querySelector('.b-matrix'); var input = document.querySelector('input'); if (tableBox.contains('<span></span>'.className == 'result')) { for (var i = 1; i < elem.length; i++) { for (var j = 1; j < elem.length; j++) { input.setAttribute('placeholder', 'a ' + i + ',' + j); } } } })(); But so far my knowledge of JS is not enough to solve this, as I understand it, simple task. Please give advice on how to solve it. Thank you in advance.
pure-js- Grundyjavascriptlabel for this - Grundyelem.legnth, BUTelemnot declared anywhere. How so? Or did you not add something to the code? - Vasily Barbashev