To change onclick attribute with JavaScript, we set the onclick
property.
For instance, we write
document.getElementById(id).onclick = () => {
//...
};
to get the element with getElementById
.
Then we set its onclick
property to the click handler to set the onclick
attribute value.