quiero cambiar el color de este div cuando hago clic en él trato de usar este javascript pero nada,
const buttonChange = () => { const button = document.querySelector('.uno'); button.addEventListener('click', () => { button.classList.toggle('.uno-active'); }) } .uno{ color: rgb(12, 114, 231); background-color: rgb(255, 255, 255); } .uno-active{ color: rgb(255, 255, 255); background-color: rgb(11, 28, 47);; } <div> <p class="uno">COSA È</p> </div>/////////////////////////////////
Debe llamar a la función buttonChange() si desea manejar el evento de clic. Además, no tiene que poner un punto antes "uno-active" :
const buttonChange = () => { const button = document.querySelector('.uno'); button.addEventListener('click', () => { button.classList.toggle('uno-active'); }); } buttonChange(); .uno{ color: rgb(12, 114, 231); background-color: rgb(255, 255, 255); } .uno-active{ color: rgb(255, 255, 255); background-color: rgb(11, 28, 47); } <div> <p class="uno">COSA È</p> </div>