Skip to content

Instantly share code, notes, and snippets.

@jcottrell
Last active August 16, 2016 21:34
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 jcottrell/bcbb32a5d340b0b762325d1931669003 to your computer and use it in GitHub Desktop.
Save jcottrell/bcbb32a5d340b0b762325d1931669003 to your computer and use it in GitHub Desktop.
Using detach to fix View All in navigation
var viewAll1 = function (e) {
e.preventDefault();
$me = $(this);
$kids = $me.parent().find('.children').detach();
$me.closest('.children').
find('li:hidden').
show().
end().
after($kids).
end().
hide();
};
var viewAll2 = function (e) {
e.preventDefault();
$me = $(this);
$myParent = $me.parent();
$kids = $myParent.find('.children').detach();
$gParent = $me.closest('.children');
$gParent.
find('li:hidden').
show().
end().
after($kids).
prepend($myParent.detach());
$me.hide();
}
@jcottrell
Copy link
Author

jcottrell commented Aug 16, 2016

Then call it with your click handler - $('.view-all').on('click', viewAll2);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment