I've been working on a project involving generating and changing a <div>. Anyways, it would be a pain to have to do <div id="drawn" onclick="changeColor(this)"></div> for 80 divs which I am working with.
I decided to use the addEventListener() function to enable an events to happen when clicked.
What I am trying to do is when a <div> is clicked, the color of it's background is changed.
When I try the code I am using, I get an Uncaught TypeError: Cannot set property 'backgroundColor' of undefined ' of null in the Javascript Console.
Here is my code:
function color(elment) {
elment.style.backgroundColor="orange"
}
document.getElementById("drawn").addEventListener("click", color(this), false)
What is causing the error in this code?