Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
90
rated 0 times [  92] [ 2]  / answers: 1 / hits: 72966  / 12 Years ago, sun, august 5, 2012, 12:00:00

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.


More From » jquery

 Answers
27

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);
});

[#83843] Friday, August 3, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckaylab

Total Points: 311
Total Questions: 120
Total Answers: 93

Location: Montenegro
Member since Thu, Jun 16, 2022
2 Years ago
;