When I put this code in HTML file, my slideshow works, but when I put it in an external js file, the slideshow doesn't work. why?
https://i.stack.imgur.com/5KtOK.jpg ............................................................
full code html: https://pastebin.com/YiZhpYzk javascript file: https://pastebin.com/11BNhL7G
var myIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
myIndex++;
if (myIndex > x.length) {myIndex = 1}
x[myIndex-1].style.display = "block";
setTimeout(carousel, 1300);
}
... Your code is work pefectly, but is being called before the your html code is bind.
– MarcusVinnicius Jan 06 '19 at 12:30