I'm brand new to JavaScript, trying to add a simple event listener, to console.log a chosen color value from an input that the script appends to a div on page-load.
HTML:
<html>
<div id="myDiv">
</div>
</html>
JavaScript:
/* First add an input color selector as a child of #myDiv
with a datalist of available colors */
document.querySelector("#myDiv").innerHTML += `
<input id="myInput" type="color" list="presetColors"
colorpick-eyedropper-active="false">
<datalist id="presetColors">
<option>#0275d8</option>
<option>#5cb85c</option>
</datalist>
`;
/* Trying to console.log the color value
that was chosen in the input */
function myFunction(event) {
console.log(event.value);
}
/* Adding an event listener so that when the color
in the input changes, the function is called */
document
.querySelector("#myInput")
.addEventListener("change", myFunction(e));
Here's a JSFiddle to play with.
I don't understand the error message "<a class='gotoLine' href='#62:1'>62:1</a> ReferenceError: e is not defined"
I mean, it says here on MDN:
The JavaScript exception "variable is not defined" occurs when there is a non-existent variable referenced somewhere.
So how to I pass the value of the input to the function?