It is necessary on the page to change the information after a certain period of time, for example, once a day.

For example, there are three divs, they are hidden through css, you need to make one of the divs visible every day, at 12 o'clock. the next day hide the current div, and show another.

I do not know what even to implement. Most likely on php, because js is attached to the front, and here you need a timer independent of page reloads

  • one
    It seems you yourself answered your question. php date, if else - Artem Gorlachev
  • A "timer independent of page reloads" is the current time;) - Gleb Kemarsky

1 answer 1

Better to do it on JS. For example as follows:

//Задаем дату от которой будет веститсь отсчет показов var startDate = new Date(2016, 8, 1, 12) var div = [] div[0] = document.getElementsByClassName('day1')[0] div[1] = document.getElementsByClassName('day2')[0] div[2] = document.getElementsByClassName('day3')[0] function millisecondsToDays(milliseconds) { return Math.floor(milliseconds/1000/60/60/24) } function updateVisibility() { //Скрываем все элементы div.forEach(function(item) { item.style.display = 'none'; }) var now = new Date(); //Открываем элемент, который должен быть показан сегодня div[millisecondsToDays(now - startDate) % div.length].style.display = 'block'; //Рассчитываем время до следующего обновления var nextUpdate = Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, 12) //Ставим таймер на следующее обновление setTimeout(updateVisibility, nextUpdate - now) } updateVisibility(); 
 <div class="day1">1</div> <div class="day2">2</div> <div class="day3">3</div> 

Update: to show all the elements, you can use a similar function.

 function showAll() { div.forEach(function(item) { item.style.display = 'block'; }) }