jQuery is just a library of techniques. Once it's on the page, you may use its functions. Putting things in the $(document).ready function is not the best way for all cases. Most code that makes use of jQuery has some things inside doc ready and other things outside of it. If you just want a transition, as long as the elements are already on the page, you can do it an any time, like:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
</head>
<body>
<div id="mydiv">Click Me!</div>
<script type="text/javascript">
$('#mydiv').click(function(){$(this).fadeOut(3000, function(){$(this).show(1000);});});
</script>
</body>
</html>
If you want to use doc ready you can put it in the head:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function($){
$('#mydiv').click(function(){$(this).fadeOut(3000, function(){$(this).show(1000);});});
});
</script>
</head>
<body>
<div id="mydiv">Click Me!</div>
</body>
</html>
Bookmarks