Element addEventListener() Method - Pass parameter values when using the addEventListener() method - Javascript DOM

Javascript examples for DOM:Element addEventListener

Description

Element addEventListener() Method - Pass parameter values when using the addEventListener() method

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button id="myBtn">Test</button>

<p id="demo"></p>

<script>
var p1 = 5;
var p2 = 7;

document.getElementById("myBtn").addEventListener("click", function() {
    myFunction(p1, p2);
});//  www.j a va  2s. c  o  m

function myFunction(a, b) {
    var result = a * b;
    document.getElementById("demo").innerHTML = result;
}
</script>

</body>
</html>

Related Tutorials