Last active
December 27, 2015 20:09
-
-
Save martynchamberlin/7382770 to your computer and use it in GitHub Desktop.
Simple show/hide structure. I build this an absolute ton and need a place to reference it so I'm not constantly writing the same thing over and over again. The beauty of this structure is that you can have an unlimited number of .toggle elements on a page and there will not be any conflict. No unique IDs required.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="toggle"> | |
<a href="#" class="read-more">Read more</a> | |
<div class="hidden hiding" style="display:none">This text toggles back and forth</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).read(function( $ ) | |
{ | |
$('.read-more').click(function() | |
{ | |
var hidden = $(this).closest('.toggle').find('.hidden'); | |
if ( $(hidden).is('.hiding')) | |
{ | |
$(hidden).removeClass('hiding').fadeIn('slow'); | |
} | |
else | |
{ | |
$(hidden).addClass('hiding').hide(); | |
} | |
return false; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment