I managed to successfully code buttons that control an auto-advancing slideshow. While both buttons are functional, only the next button is able to cycle through all images. However, when using the previous button to navigate back to the beginning, the whole function breaks and error messages pop up stating that it cannot locate inactive or active elements.
What could I be overlooking?
document.getElementById('next1').onclick = function() {
var lon = items.length;
items[ptr].className= "inactive";
if(ptr==lon-1){
ptr=0;
}
ptr++;
items[ptr].className = "active";
}
document.getElementById('previous1').onclick = function() {
var lon = items.length;
var p = ptr-1;
items[ptr].className= "inactive";
if(ptr==lon){
ptr=items.length;
}
ptr--;
items[ptr].className = "active";
}