Skip to content
Advertisement

javascript carousel not showing first slide

So i took this code off of w3schools to try and learn how to build a carousel from scratch and adapted IT to my own project but i’ve run into a problem where it won’t show the first slide by default when the page loads. the carousel works fine otherwise once you click on the balls(dots?) meant to control it.

DEFAULT SLIDE NOT SHOWING

1

here is the html, css and javascript code..

JavaScript
JavaScript
JavaScript

Any help is greatly appreciated!

NOTE: i have a display: none; line in CSS meant to stop all the slides from showing up at once, if i remove it they stack up on the page so i don’t think that’s the problem.

Tried changing the loops to see if i had typed something wrong but it didn’t work

Advertisement

Answer

If you are using an external JavaScript file then you can call the function by adding event listeners in the JavaScript file.

Otherwise, you need to create tag and write the whole javascript code. Then it will work.

JavaScript
JavaScript
JavaScript
Advertisement