Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Last active May 22, 2019 01:14
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 walterdavis/b53174947ca0c007d91c6e03144a9204 to your computer and use it in GitHub Desktop.
Save walterdavis/b53174947ca0c007d91c6e03144a9204 to your computer and use it in GitHub Desktop.
// find all the divs with the class name 'more', and hide them
$$('div.more').invoke('hide');
// "listen" for clicks on any link with the class name 'more', and respond...
$(document).on('click', 'a.more', function(evt, elm){
// first, stop any normal reaction, like scrolling back to the top of the browser window
evt.stop();
// starting from the link that was clicked, look up to its containing element...
// then select the following div with the class name 'more', and if it's hidden, show it, or vice-versa
elm.up().next('div.more').toggle();
// toggle the text inside the link that was clicked
elm.update((elm.innerText == 'more' ? 'less' : 'more'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment