Skip to content

Instantly share code, notes, and snippets.

@lode
Last active December 17, 2015 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lode/5630349 to your computer and use it in GitHub Desktop.
Save lode/5630349 to your computer and use it in GitHub Desktop.
revealElement CitySessies
<div class="revealElement" title="Klik hier">
extra inhoud
</div>
... zorgt voor ...
<a href="#">Klik hier</a>
<div class="revealElement" title="Klik hier">
extra inhoud
</div>
... waarbij de div display none is en de link de div toggled
<div class="revealElement" id="revealElementSomeName">
extra inhoud
</div>
<p>blah <a href="#" id="revealElementSomeNameLink">foo</a> bar</p>
... waarbij er geen extra link wordt toegevoegd en de bestaande link wordt gebruikt (om de div aan en uit te zetten)
function revealElements() {
$('.revealElement').each(function(){
var self = this;
$(this).hide();
var customRevealLink = $('#' + $(this).attr('id') + 'Link');
if (customRevealLink.length) {
$(customRevealLink).click(function(event) {
event.preventDefault();
$(self).toggle(100);
});
}
else {
var revealElementLinkTitle = $(this).attr('title');
var revealElementLink = $('<p><a class="revealElementLink" href="#show">'+ revealElementLinkTitle +'</a></p>');
$(this).before(revealElementLink);
$(this).prev().click(function() {
$(this).next().toggle(100);
});
}
});
}
revealElements();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment