seanrf123 seanrf123 - 2 months ago 7
HTML Question

Add settimeout between my get ellements inside one function

I need to add a settimeout between the get elements not sure how to set this out can anyone help

<p id="demo" >Click me to change my HTML content (innerHTML).</p>

<p id="emo" >Click me to change my HTML content (innerHTML).</p>

<button id="addto4" style="display:none;" onclick="myFunction()">change</buton>

<button id="addto3" onclick="myFunction1()">change2</buton>


<button type="button" class="btn btn-default" onclick="myFunction2()">Add all</button>


<script> function myFunction2() {
document.getElementById('addto3').click(),
document.getElementById('addto4').click(); } </script>

Answer

You need to split your method in 2 and call the 2nd part after the timeout.

function f2(){
  document.getElementById('addto4').click();
}

function f1(){
  document.getElementById('addto3').click();
  setTimeout(f2, 3000);
}