A
A
Alex_Omsk2017-10-18 10:55:07
JavaScript
Alex_Omsk, 2017-10-18 10:55:07

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>

Requires a button that, when clicked, will hide rows with the same values.
As I understand it, you need to assign a class to the tr string using JS if the values ​​inside the td class="value" cells are the same. And when you click on the button, these lines will be hidden. Please help me implement

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2017-10-18
@Alex_Omsk

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 question

Ask a Question

731 491 924 answers to any question