after my countdown is over, i need to add <a href> when I click "Enter" to enter a new page, which element do I use ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

after my countdown is over, i need to add <a href> when I click "Enter" to enter a new page, which element do I use ?

<script type="text/javascript"> // Set the date we're counting down to var countDownDate = new Date("June 4, 2017 00:00:00").getTime(); // Update the count down every 1 second var countdownfunction = setInterval(function() { // Get todays date and time var now = new Date().getTime(); // Find the distance between now an the count down date var distance = countDownDate - now; // Time calculations for days, hours, minutes and seconds var days = Math.floor(distance / (1000 * 60 * 60 * 24)); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); // Output the result in an element with id="demo" document.getElementById("demo").innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s "; // If the count down is over, write some text if (distance < 0) { clearInterval(countdownfunction); document.getElementById("demo").innerHTML = "Enter"; } }, 1000); </script>

1st Jun 2017, 11:35 PM
Nelson
Nelson - avatar
4 Answers
+ 4
InnerHTML property accept Html code (not only just plain text), so you can do: document.getElementById("demo").innerHTML = "<a href='your.url'>Enter</a>"; ... even if another ways are possible, by appending some node type content ( using document.createElement('a') method to create the node to insert in the DOM with Html element appendChild() method ( for example: different ways of inserting node in DOM are available ), and setting its attributes as needed: var link = document.createElement("a"); link.href="your.url"; document.getElementById("demo").appendChild(link); [ edit ] @Joshua Hero: JQuery allows to do same, just a little shortener: it's useful only if you already knows JQuery, or plan to study it in future, but not really necessarly ;)
2nd Jun 2017, 12:42 AM
visph
visph - avatar
0
jQuery would help you...................... I think (?)
2nd Jun 2017, 12:24 AM
Hiro
Hiro - avatar
0
Thanks a lot visph, Hey Joshua, will learn jQuery, Thank you all Cheers !!
2nd Jun 2017, 10:31 AM
Nelson
Nelson - avatar
0
Good luck 😋
2nd Jun 2017, 11:26 AM
Hiro
Hiro - avatar