Adnan Niazi Adnan Niazi - 1 month ago 9
jQuery Question

I want to add a class to a div after 2 seconds of the pageload

I want to add a class to a div after 2 seconds of the pageload, please guide me how can I do it with jquery.

Answer

You can try like this.$(window).ready(function(){}) will not call till your whole page will be ready and setInterval() will call after 2 sec.

$(window).ready(function(){
  setInterval(function(){ 
    $('div').addClass("test")
  }, 2000);

});
<div>Class
</div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>