I want to pass an argument to the function that is being called inside of the event listener. The code below shows what I want to do however it is not letting me do it conventionally. What is a workaround to this?
HTML code :
<button id='btn'>Click Me</button>
JavaScript code :
<script>
document.getElementById('btn').addEventListener( "click",btnClick(5) );
function btnClick(argument)
{
console.log("Button clicked with argument : " + argument);
}
</script>
Console should read :
Button clicked with argument : 5
Thanks guys.