Jump to content
Philades

Multiple Slideshows on one page

Recommended Posts

Hi everyone. I need help.  I am using this slideshow https://www.w3schools.com/howto/howto_js_slideshow.asp for a new site I'm building.  I want to to put multiple slideshows on the same page.  I can't seem to find out how to target each java script to each slideshow. What happens is that each "dot" will change the pictures on the same slideshow.  Let me know if you need any other details.  Thanks so much in advance!

Edited by Philades

Share this post


Link to post
Share on other sites

That doesn't use jQuery.  But it's set up to assume just a single one.  If you want multiple ones on the same page then you need to distinguish each one, and you need to adjust the code to look for a specific one.  For example, in the main container you could give each one a unique ID.  Then, in the Javascript code, you get use getElementById to get a reference to the parent container, and then use that to get the child elements with the various class names.  If you use the document object it's going to find elements with that class all over the document, but if you use rootElement.getElementsByClassName then it will only get the elements with the class which are children of rootElement, whatever you set that to.  It also uses a global variable called slideIndex, you'll also need to change that to something like an array so that you can have one index per slideshow ID.  You'll also need to change the click handlers to pass and use the slideshow ID, so instead of, for example, currentSlide(2), you would do currentSlide(2, 'slideshow2') where you pass the ID for the slideshow container so that everything is looking up the data and elements based on a unique ID for each slideshow.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×