If you have a show and hide class on the elements you can identify them.
Loop the elements with the hide class and remove it, then add the show class. Use the event target to get to the container of the click target and add the hide class to it.
That’s basically what you were doing in your original page before you pulled the code out.
It’s similar to the code in my demo except I used data attributes to point to the page required and my example will do pagination simply by adding another button and putting a data attribute on it.
The pagination is no problem but the bigger problem is in resetting the videos which was built in to your original. There is also the questions of animation on each page which you seem to have removed now.
Endlessly tweaking something is not a viable way to build as you just end up bending code to do something it wasn’t designed for.
In that page you’d need to set up the actions you want to happen in the exit button click handler. At the moment all you have is a scrollTo routine there.
You would need to fill in these details.
function exitClickHandler(e) {
if (e.target.classList.contains("exitpPage2")) {
// show page2 and do all the stuff you need here.
// e.g. show container2 and hide container 3 and 1
// hide / reset running videos etc.
console.log('Page2');
}
if (e.target.classList.contains("exitpPage3")) {
// show page3 and do all the stuff you need here.
// e.g. show container3 and hide container 2 and 1
// hide / reset running videos etc.
console.log('Page3');
}
window.scrollTo(0, 0);
}
function exitClickHandler(e) {
if (e.target.classList.contains("exit")) {
// show exitpPage2 and do all the stuff you need here.
// e.g. show container2 and hide container 2 and 3
// hide / reset running videos etc.
console.log('Page1');
}
if (e.target.classList.contains("exitPage2")) {
// show page2 and do all the stuff you need here.
// e.g. show container2 and hide container 1 and 3
// hide / reset running videos etc.
console.log('Page2');
}
if (e.target.classList.contains("exitPage3")) {
// show page3 and do all the stuff you need here.
// e.g. show container3 and hide container 2 and 1
// hide / reset running videos etc.
console.log('Page3');
}
window.scrollTo(0, 0);
}