www.broadwayinvictoria.com functions fine with the existing jquery and javascript (please visit site to check out Source Code). However, am encountering a javascript conflict locally when I add a slider to the Home Page. The 'slider.js' file functions properly on its own locally as does the Home Page jquery and javascript without the slider.
What have I tried?
- Researched various forums, YouTube and documentation on the jQuery site.
- Am aware of the '$' conflict, and have learned about and tried jQuery.noconflict without success.
- Reordered where jquery and .js files are located (all in the Head, all just before closing
</body>
tag) and the sequence in which they are laid out, one-over-the-other. - 'slider.js' Prior to creating the external 'slider.js' file, I had this script added and placed just before the closing
</body>
tag of the index file. - Viewing the 'slider.js' file in Google Developer Tools / Sources There is an error on the second last line of code:
That code is on the next line:
slides[slideIndex-1].style.display = "block";
This is what the accompanying error message says: "Uncaught TypError: Cannot read property 'style' of undefined"
-----For Reference 'slider.js' follows between the dotted lines -------
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("slideshow-container");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
----------- END of 'js.file' -------------------------
Appreciate your insight and guidance. Let me know if I need to clarify anything.
tag as you had alluded to - listed above in Item 3 . Can you please explain how to wrap slider.js in an IIFE? All this new to me.
– D Convention Oct 27 '16 at 15:59