Skip to content

Instantly share code, notes, and snippets.

@jentanbernardus
Created June 17, 2012 06:30
Show Gist options
  • Save jentanbernardus/2943713 to your computer and use it in GitHub Desktop.
Save jentanbernardus/2943713 to your computer and use it in GitHub Desktop.
Simple jQuery Toggle Javascript snippet
<a href="#" id="toggleButton">Click Here</a>
<div id="toggleSection">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script type="text/javascript" src="js/toggle.js"></script>
$(document).ready(function() {
$('.toggleButton').click(function() {
if ($('.toggleSection').is(":hidden"))
{
$('.toggleSection').slideDown("slow");
} else {
$('.toggleSection').slideUp("slow");
}
return false;
});
});
@julioest
Copy link

In the html you're giving them IDs; In JS you're calling Classes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment