On my html I have multiple tables, which are for different valuations. The results of those valuations are supposed to be in another table. The text of valuation_all
in the tables.taglist
should be transferred into another table. I'm really lost here. Newby with this topic so I'll appreciate every help!
Table for summary results
<table id="results" class="summary">
<th>Test</th>
<th>result</th>
<tr>
<td>E-01</td>
<td>text</td>
</tr>
<tr>
<td>E-02</td>
<td>text</td>
</tr>
</table>
Tables of valuation
<p>
<table id="results1" class="taglist">
<th>Name</th>
<th>result</th>
<tr>
<td class="valuation">FAIL</td>
<td rowspan=2 class="valuation_all">FAIL</td>
</tr>
<tr>
<td class="valuation">PASS</td>
</tr>
</table>
</p>
<p>
<table id="results2" class="taglist">
<th>Name</th>
<th>result</th>
<tr>
<td class="valuation">x</td>
<td class="valuation_all" rowspan=2>OPEN</td>
</tr>
<tr>
<td class="valuation">x</td>
</tr>
</table>
</p>
Assuming your results list tables are ordered the same way you ordered rows in your global results table, you can perform a forEach
on all .valuation_all
, and then mirror each text on the global results table:
const resTables = document.querySelectorAll('.valuation_all') const results = document.querySelectorAll('#results tr > td + td') resTables.forEach( function(el, i) { results[i].textContent = el.textContent })
<table id="results" class="summary"> <tr> <th>Test</th><th>result</th> </tr> <tr> <td>E-01</td><td>text</td> </tr> <tr> <td>E-02</td><td>text</td> </tr> </table> <hr> <table id="results1" class="taglist"> <tr> <th>Name</th><th>result</th> </tr> <tr> <td class="valuation">FAIL</td><td rowspan="2" class="valuation_all">FAIL</td> </tr> <tr> <td class="valuation">PASS</td> </tr> </table> <table id="results2" class="taglist"> <tr> <th>Name</th><th>result</th> </tr> <tr> <td class="valuation">x</td><td class="valuation_all" rowspan="2">OPEN</td> </tr> <tr> <td class="valuation">x</td> </tr> </table>
Please consider using data attributes for better matching. https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
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.