addEventListener("click", myFunction); - Javascript DOM Event

Javascript examples for DOM Event:addEventListener

Description

The onclick event occurs when the user clicks on an element.

Summary

Bubbles Yes
Cancelable Yes
Event type: MouseEvent
Supported HTML tags: All HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo">Click me.</p>

<script>
document.getElementById("demo").addEventListener("click", myFunction);

function myFunction() {/*from  w w  w  . ja  v a 2s .  com*/
    document.getElementById("demo").innerHTML = "YOU CLICKED ME!";
}
</script>

</body>
</html>

Related Tutorials