‘Hi, when i click on "a" element i wanna show only one div (other div’s supposed to be hide).
Now when i click on "box1"
, .dayone
is showed, next… when i click on "box2"
i see .dayone
and .daytwo
.’
function openInfo1() {
const currentTime = new Date()
const day = currentTime.getDate()
if (day > 1) {
document.querySelector(".dayone").style.display = "flex";
}
}
function openInfo2() {
const currentTime = new Date()
const day = currentTime.getDate()
if (day > 2) {
document.querySelector(".daytwo").style.display = "flex";
}
}
function openInfo3() {
const currentTime = new Date()
const day = currentTime.getDate()
if (day > 3) {
document.querySelector(".daythree").style.display = "flex";
}
}
.dayone,
.daytwo,
.daythree {
display: none;
}
<div class="txtelem">
<div class="dayone">1</div>
<div class="daytwo">2</div>
<div class="daythree">3</div>
</div>
<div class="boxelem">
<a class="box1" onclick="openInfo1()">
<img class="nb1" src="//placehold.co/50" />
</a>
<a class="box2" onclick="openInfo2()">
<img class="nb2" src="//placehold.co/51" />
</a>
<a class="box3" onclick="openInfo3()">
<img class="nb3" src="//placehold.co/52" />
</a>
</div>
2
Answers
I suggest you delegate and simplify the classes
I removed the dat code since that does not seem to be what you actually want. The links would not work if the day is not what is expected and that would be weird UX. I can add them back if you need
You could try using jQuery for this
HTML
jQuery