Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delay Removing a Class in Jquery [duplicate]

Possible Duplicate:
Jquery delay execution of script

I am writing a small script that, when the page loads, assigns a CSS subclass to three elements. 800ms later, I want it to remove that subclass.

I thought this code might do it:

<script type="text/javascript">
$(document).ready(function () {


        $("#rowone.one").addClass("pageLoad");
        $("#rowtwo.three").addClass("pageLoad");
        $("#rowthree.two").addClass("pageLoad");

        .delay(800);    
        $("#rowone.one").removeClass("pageLoad");
        $("#rowtwo.three").removeClass("pageLoad");
        $("#rowthree.two").removeClass("pageLoad");

})
</script>

Sadly it doesn't, any help would be much appreciated. Thanks in advance.

like image 436
baxterma Avatar asked Aug 05 '12 10:08

baxterma


People also ask

How to remove Class after delay jQuery?

If you have it applied to an element but want to remove it from an element after a designated amount of time has passed, you can do so by using jQuery's . setTimeout() method. var header = $('#header'); header. addClass('blue'); setTimeout(function() { header.

How to set delay in jQuery?

jQuery delay() Method The delay() method sets a timer to delay the execution of the next item in the queue.


1 Answers

You can use setTimeout() function:

Calls a function or executes a code snippet after specified delay.

$(document).ready(function () {
   var $rows = $("#rowone.one, #rowtwo.three, #rowthree.two").addClass("pageLoad");

   setTimeout(function() {
       $rows.removeClass("pageLoad");
   }, 800);
});
like image 189
undefined Avatar answered Oct 14 '22 18:10

undefined