Created
July 8, 2023 14:26
-
-
Save rushkeldon/23ae1abb617b006d2b9c074e2e5524cd to your computer and use it in GitHub Desktop.
next slide please - now
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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