Javascript examples for DOM Event:Element Event Attribute
The onclick event occurs when the user clicks on an element.
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> |
<!DOCTYPE html> <html> <body> <p id="demo">Click me.</p> <script> document.getElementById("demo").onclick = function() {myFunction()}; function myFunction() {/*from w ww . j a v a 2s . c o m*/ document.getElementById("demo").innerHTML = "YOU CLICKED ME!"; } </script> </body> </html>