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

Javascript examples for DOM:Document addEventListener

Description

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

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

document.addEventListener("click", function() {
    myFunction(p1, p2);
});//  w  ww  .ja  v  a  2 s.co m

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

</body>
</html>

Related Tutorials