Skip to content

Instantly share code, notes, and snippets.

@mgalgs
Created July 18, 2011 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgalgs/1090551 to your computer and use it in GitHub Desktop.
Save mgalgs/1090551 to your computer and use it in GitHub Desktop.
jQuery Toggle html characters +/-
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('a.toggler').click(function() {
var $this = $(this);
console.log($this.next(".hidden"));
$this.next(".hidden").slideToggle("fast", function() {
$this.find('span').text($(this).is(':visible') ? '-' : '+');
});
});
});
</script>
<style type="text/css" media="screen">
.hidden {
display: none;
}
</style>
</head>
<body>
<a href="#" class="toggler"><span>+</span> toggle</a>
<div class="hidden">
Hidden
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment