In JavaScript:
object.onclick = function(){
myScript};
This example uses the HTML DOM to assign an "onclick" event to a p element.
<!DOCTYPE html> <html> <body> <p id="demo">Click me.</p> <script> document.getElementById("demo").onclick = function() {myFunction()}; function myFunction() {/*from ww w . java 2s.c om*/ document.getElementById("demo").innerHTML = "YOU CLICKED ME!"; } </script> </body> </html>
Bubbles: Cancelable: Event type: Supported HTML tags: | Yes Yes MouseEvent All HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title> |
---|