Lewis Day Lewis Day - 11 months ago 71
Javascript Question

display span class in after set time

What I'm trying to achieve is using javascript display both these spans after five seconds for the first one and 10 seconds for the second one.

<span class="5-seconds">Connecting...</span>
<span class="10-seconds">Connection Established<span>

unsure on how I would achieve this just using javascript thank-you for the help.

Answer Source

Use SetTimeout

Here,initially i made both spans to display:none,5seconds after html is completely rendered im showing up first div and after 10seconds second div is shown

window.onload = function() {
  ShowSpans('first', 5);
  ShowSpans('second', 10);

function ShowSpans(classname, time) {
  setTimeout(function() {

    document.getElementsByClassName(classname)[0].style.display = "block";
  }, time * 1000);

span {
  display: none;
<span class="first">Connecting...</span>
<span class="second">Connection Established<span>

Hope this helps