Skip to content

Instantly share code, notes, and snippets.

@twalker
Created June 16, 2010 02:15
Show Gist options
  • Save twalker/440047 to your computer and use it in GitHub Desktop.
Save twalker/440047 to your computer and use it in GitHub Desktop.
A tiny jQuery plugin to reveal a target element from a triggering link.
/*
* revealMore
*
* A tiny jQuery plugin to reveal a target element from a triggering link.
*
* Usage:
* <a class="more_trigger" href="#more1">more...</a>
* <div id="more1">More Info</div>
*
* <script type="text/javascript">
* $("a.more_trigger").revealMore({moreText: 'more stuff', lessText: 'less stuff'});
* </script>
*/
(function($) {
$.fn.revealMore = function(params) {
var options = $.extend({
moreText: 'more...',
lessText: 'less...'}, params);
return this.each(function() {
var $lnk = $(this), $target = $($lnk.attr('href'));
if($target.length == 0) {
$lnk.hide();
} else {
$target.hide();
}
$lnk.toggle(
function(e){
e.preventDefault();
$(this).text(options.lessText).addClass('less');
$($(this).attr('href')).slideDown('fast');
},
function(e){
e.preventDefault();
$(this).text(options.moreText).removeClass('less');
$($(this).attr('href')).slideUp('fast');
}
);
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment