<td data-date="2017-02-30" style="text-align: center; height: 132.8px;"></td> 

There is this item. How can I make it display none if data-date="2017-02-30"

  • How does the data-table change? Or is it somewhere generated code and it needs to be converted? - user207618

1 answer 1

 (function() { var td = document.querySelectorAll('table td'), // Получаем все td date = '2017-02-30'; // Нужная дата // Цикл всех td for(var i = 0; i < td.length; i++){ var dateTd = td[i].getAttribute('data-date'); // Получаем содержимое атрибута data-date // Проверяем, равно ли значение из атрибута с переменной даты сверху if(dateTd == date){ td[i].style.display = 'none'; // Если да, то скрываем td }; }; }()); 
 <table> <tbody> <tr><td data-date="2017-02-30" style="text-align: center; height: 132.8px;">Блок 1</td></tr> <tr><td data-date="2017-02-31" style="text-align: center; height: 132.8px;">Блок 2</td></tr> </tbody> </table> 

  • Your code works fine, but on the dates that are now shown in the schedule (the site puaroquest.ru is a schedule closer to the end of the page, but the problem is that the date is needed to be loaded later and on a date that is not visible does not work as it should. Look? - Mimzik
  • @Mimzik, why don't you run this function every time dates are loaded? Or check the dates that are loaded? The bottom line is that you do not have these clarifications in the question. Ask a new question about this topic - Yuri