Search code examples
javascripthtmlfunctiononclickdelay

How do I make a delay on a onclick display to none function


I have this script, but i there needs to be a 2sec. delay from I click on the 'playblock'-function, till it happens.

<script type="text/javascript">
function playblock()
{
 document.getElementById("playbox").style.display="none";    
}
</script>

Solution

  • Use a timeout:

    function playblock() {    
      window.setTimeout(function(){ document.getElementById("playbox").style.display="none"; }, 2000);
    }