Skip to content

Instantly share code, notes, and snippets.

@aeruo
Last active September 8, 2023 10:47
Show Gist options
  • Save aeruo/ea3276da5fe32852b768671427e9891b to your computer and use it in GitHub Desktop.
Save aeruo/ea3276da5fe32852b768671427e9891b to your computer and use it in GitHub Desktop.
jQuery script for page handling, making it easier to contain multiple pages within one html file.
$(function(){
//when a button is clicked
$('.page-button').on('click', function(){
// Get the target page
var $target = $(this).attr('data-target');
var $targetSelector = 'section#' + $target;
// Show target page
$($targetSelector).removeClass('page-hidden');
$($targetSelector).addClass('page-visible');
// Hide everything page
$('section.page:not(' + $targetSelector + ')').removeClass('page-visible');
$('section.page:not(' + $targetSelector + ')').addClass('page-hidden');
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment