Answer the question
In order to leave comments, you need to log in
How to hide duplicate rows in comparison using JS?
Good day!
I'm making a comparison module for a website. When comparing several products, the data is displayed in a table of the form:
<table name="table">
<tbody>
<tr>
<td class="option">Диагональ экрана</td>
<td class="value">82 см</td>
<td class="value">82 см</td>
<td class="value">102 см</td>
</tr>
<tr>
<td class="option">Технология</td>
<td class="value">LED</td>
<td class="value">LED</td>
<td class="value">LED</td>
</tr>
<tr>
<td class="option">Разрешение экрана</td>
<td class="value">1920x1080</td>
<td class="value">1920x1080</td>
<td class="value">1920x1080</td>
</tr>
<tr>
<td class="option">Поддержка SmartTV</td>
<td class="value">Да</td>
<td class="value">Нет</td>
<td class="value">Нет</td>
</tr>
</tbody>
</table>
Answer the question
In order to leave comments, you need to log in
Search all rows querySelectorAll(tr) Select
cells in each row (querySelectorAll again) Get
values
Take value from first cell, compare with others (every)
Apply class if needed
https://jsfiddle.net/twr5L9aa/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question