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.
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.
jQuery delay() Method The delay() method sets a timer to delay the execution of the next item in the queue.
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With