Friday, January 2, 2009

[jQuery] Sleep / Delay in jQuery

Hello,

I'm a newbie to jQuery and was going through the hello world of
jQuery as per - http://docs.jquery.com/How_jQuery_Works

I've gotten my code to the stage
----------------------------------------------------------------------------------------------------
[yvb@bfc22 basics]$ cat test3.html
<html>
<head>

<style type="text/css">
a.test { font-weight: bold; }
</style>

<script type="text/javascript" src="/jquery.js"></script>
<script type="text/javascript">
// Your code goes here
$(document).ready(function(){
// Your code here
$("a").addClass("test");
$("a").click(function(event){
alert("As you can see, the link no longer took you to
jquery.com");
event.preventDefault();
});
$("a").removeClass("test");
});
</script>

</head>

<body>
<a href="http://jquery.com/">jQuery</a>
</body>

</html>
----------------------------------------------------------------------------------------------------

Now the timing between addClass and removeClass is too short. Is there
a way for me to add a delay of 1 second before addClass and another
second after addClass functions ?

Thanks.

Yashesh

No comments: