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" >
<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" >
<th>Name</th>
<th>result</th>
<tr>
<td >FAIL</td>
<td rowspan=2 >FAIL</td>
</tr>
<tr>
<td >PASS</td>
</tr>
</table>
</p>
<p>
<table id="results2" >
<th>Name</th>
<th>result</th>
<tr>
<td >x</td>
<td rowspan=2>OPEN</td>
</tr>
<tr>
<td >x</td>
</tr>
</table>
</p>
CodePudding user response:
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" >
<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" >
<tr>
<th>Name</th><th>result</th>
</tr>
<tr>
<td >FAIL</td><td rowspan="2" >FAIL</td>
</tr>
<tr>
<td >PASS</td>
</tr>
</table>
<table id="results2" >
<tr>
<th>Name</th><th>result</th>
</tr>
<tr>
<td >x</td><td rowspan="2">OPEN</td>
</tr>
<tr>
<td >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