Postingan lainnya
Kelas Premium!
Belajar Javascript untuk website
Gunakan kupon "mulaijs" untuk diskon 75 ribu!
show/hide di tiga waktu yang berbeda javascript
membuat show/hide
- show only 12.00 -14.00 id "malam" show, other id hide.
- show only 17.00 - 03.00 id "pagi" show, other id hide.
- show 07.00 - 10.00 span "siang" show, other id hide
<span id="malam" style="background-color:magenta;"> malam </span>
<br/>
<span id="pagi" style="background-color:cyan;"> pagi </span>
<br/>
<span id="siang" style="background-color:orange;"> siang </span>
<script>
var start = new Date();
var end = new Date();
var time = new Date().getTime();
if (time > start.setHours(12,00) && time < end.setHours(14,00)){
document.getElementById("malam").style.display = "block";
document.getElementById("pagi").style.display = "none";
document.getElementById("siang").style.display = "none";
}
else if (time > start.setHours(07,00) && time < end.setHours(10,00)){
document.getElementById("malam").style.display = "none";
document.getElementById("pagi").style.display = "block";
document.getElementById("siang").style.display = "none";
}
else (time > start.setHours(17,00) && time < end.setHours(03,00)){
document.getElementById("malam").style.display = "none";
document.getElementById("pagi").style.display = "none";
document.getElementById("siang").style.display = "block";
}
else {
document.getElementById("malam").style.display = "none";
document.getElementById("pagi").style.display = "none";
document.getElementById("siang").style.display = "none";
}
1 Jawaban:
<div>coba kodenya dibuat seperti ini: </div><pre><span id="malam" style="background-color:magenta;"> malam </span> <br/> <span id="pagi" style="background-color:cyan;"> pagi </span> <br/> <span id="siang" style="background-color:orange;"> siang </span>
<script> var pagi = document.getElementById("pagi") var siang = document.getElementById("siang") var malam = document.getElementById("malam") var time = new Date().getHours();
if(time &gt;= 12 &amp;&amp; time &lt;= 14){
malam.style.display = "block";
pagi.style.display = "none";
siang.style.display = "none";
}
else if(time &gt;= 17 || time &lt;= 3){
malam.style.display = "none";
pagi.style.display = "none";
siang.style.display = "block";
}
else if(time &gt;= 7 &amp;&amp; time&lt;= 10){
malam.style.display = "none";
pagi.style.display = "block";
siang.style.display = "none";
}
else{
malam.style.display = "none";
pagi.style.display = "none";
siang.style.display = "none";
}
</script></pre><div><br><br></div>