Skip to content

Instantly share code, notes, and snippets.

@rushkeldon
Created July 8, 2023 14:26
Show Gist options
  • Save rushkeldon/23ae1abb617b006d2b9c074e2e5524cd to your computer and use it in GitHub Desktop.
Save rushkeldon/23ae1abb617b006d2b9c074e2e5524cd to your computer and use it in GitHub Desktop.
next slide please - now
// pick an easy element from the dom
const bar = document.querySelector( '.nav-primary' );
// listen for the click event and nextSlide
bar.addEventListener( 'click', nextSlide );
/*
* Sample URL :
* https://definition.org/meghan-markle-facts/40/
*/
function nextSlide(){
const hrefArray = String( window.location.href ).split( '/' );
const slideIndex = parseInt( hrefArray[ 4 ] );
const nextSlideIndex = slideIndex + 1;
hrefArray[ 4 ] = String( nextSlideIndex );
const newHref = hrefArray.join( '/' );
window.location.href = newHref;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment