window.addEventListener("DOMContentLoaded", function() {
var content = document.querySelector(".slider");
content.addEventListener("click", function(event) {
var target = event.target;
if (target = target.closest(".btn")) {
event.preventDefault();
var a = content.querySelectorAll("#redBtn, #yellowBtn, #greenBtn, #blueBtn");
var img = content.querySelectorAll(".preview");
var selected = [].indexOf.call(a, target);
[].forEach.call(a, function(el, i) {
(i == selected) ? (el.classList.add("actBtn"), img[i].classList.add("act")):
(el.classList.remove("actBtn"), img[i].classList.remove("act"))
})
}
})
});
Верно?