:target CSS something with javascript

There have a way to make with a click event for #id for example when click on it on every section that got h2 change its color?

Thanks

document.querySelectorAll(“h2”) should be helpful if you need to change all h2 color

1 Like

getElementById()

1 Like
let myDiv= document.getElementById('mydiv');
myDiv.addEventListener('click', function(){ 
     myDiv.style.color = blue;
})

MDN references
HTMLelement.style
addEventListener()

1 Like