// 컬러리스트 선택자 변수 const year = document.querySelector("#copy .year"); const bgColor = document.querySelector("#color_bg"); const bgInnerTitle = document.querySelector("#color_bg h1"); const bgInnerText = document.querySelector("#color_bg p"); // 컬러리스트 const bgText = [ { year : year.innerText = "2017", color: bgInnerTitle.innerText = "Greenery", number: bgInnerText.innerText = "15-0343", bg: bgColor.style.backgroundColor = "#84bd00" }, { year : year.innerText = "2018", color: bgInnerTitle.innerText = "Ultra Violet", number: bgInnerText.innerText = "18-3838", bg: bgColor.style.backgroundColor = "#5f4b8b" }, { year : year.innerText = "2019", color: bgInnerTitle.innerText = "Living Coral", number: bgInnerText.innerText = "16-1546", bg: bgColor.style.backgroundColor = "#FF6D70" }, { year : year.innerText = "2020", color: bgInnerTitle.innerText = "Classic Blue", number: bgInnerText.innerText = "19-4052", bg: bgColor.style.backgroundColor = "#004680" } ]; // 버튼 const increase = document.querySelector("#btn .increase"); const decrease = document.querySelector("#btn .decrease"); // 감소버튼 decrease.addEventListener("click", function decreaseYear(event){ let i = 3; bgText[i -1]; console.log('hi'); }); // 증가버튼 increase.addEventListener("click", function increaseYear(){ console.log('hello'); });¿Sabes cómo hacer que funcione el botón de aumento?
Quería cambiarlo cuando presiono el botón.
Si entiendo bien su pregunta, está tratando de cambiar todo el contenido en las 4 etiquetas que ha seleccionado usando selectores de consulta. Si eso es lo que estás tratando de hacer, creo que deberías editarlos individualmente.
Como en tu disminución fn:
i--; // initialse i outside year.innerHTML = bgText[i].year; bgInnerTitle.innerHTML = bgText[i].color; ...Revisa estas preguntas:
html: cambie el valor del elemento h1 dentro de un formulario con JavaScript
color de fondo - Cómo usar JavaScript para cambiar div backgroundColor
Y preguntas similares sobre cómo cambiar las propiedades HTML usando JS y luego hacerlo uno por uno.