<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>How To Use jQuery To Make Your Content Slide Toggle</title>
<script src="jquery-1.4.js" type="text/javascript"></script>
<script type="text/javascript">
$(function($) {
$('h2').css({'cursor':'pointer'}).next().hide().prev().click(function () {
$(this).next().slideToggle();
});
});
</script>
</head>
<body>
<h1>jQuery slideToggle Demo</h1>
<h2>Click On this Heading</h2>
<ul>
<li>This is a list</li>
<li>jQuery Rocks</li>
<li>Isn't this easy?</li>
<li>You love it</li>
</ul>
<h2>This is another heading</h2>
<div>
Here is the content of the page. Blah blah jQuery is cool.
</div>
<h3>Version #1</h3>
<textarea cols="50" rows="8">
$(document).ready(function(){
$('h2').next().hide();
$('h2').click(function () {
$(this).next().slideToggle('slow');
});
});
</textarea>
<h3>Version #2: Shorter code with curser pointer</h3>
<textarea cols="50" rows="8">
$(function($) {
$('h2').css({'cursor':'pointer'}).next().hide().prev().click(function () {
$(this).next().slideToggle();
});
});
</textarea>
<p>You can <a href="jquery-slidetoggle-source.html">view the source here</a> or save this page.</p>
</body>
</html>