Document.querySelector() - Web APIs | MDN[
^]
EventTarget.addEventListener() - Web APIs | MDN[
^]
However, since you're attaching an event listener to a single element, it would be simpler to add an
id
to that element, and use
getElementById
instead of
querySelector
.
For example:
<button id="onButton" type="button">Turn on the light</button>
document.getElementById("on").addEventListener("click", function(){
document.getElementById("myImage").src = "pic_bulbon.gif";
});