HTML DOM onclick Event Last Updated : 26 Nov, 2024 Comments Improve Suggest changes Like Article Like Report The HTML DOM onclick event occurs when the user clicks on an element. In HTML:<element onclick="myScript"> HTML <!DOCTYPE html> <html> <body> <button onclick="myFunction()">Click me</button> <p id="gfg"></p> <script> function myFunction() { document.getElementById( "gfg").innerHTML = "GeeksforGeeks"; } </script> </body> </html> In JavaScript:object.onclick = function(){myScript}; HTML <!DOCTYPE html> <html> <body> <p id="gfg">Click me.</p> <script> document.getElementById("gfg").onclick = function () { GFGfun() }; function GFGfun() { document.getElementById( "gfg").innerHTML = "YOU CLICKED ME!"; } </script> </body> </html> In JavaScript, using the addEventListener() Method:object.addEventListener("click", myScript); HTML <!DOCTYPE html> <html> <body> <p id="gfg">Click me.</p> <script> document.getElementById( "gfg").addEventListener("click", GFGfun); function GFGfun() { document.getElementById( "gfg").innerHTML = "YOU CLICKED ME!"; document.getElementById( "gfg").style.color = 'red'; document.getElementById( "gfg").style.background = 'cyan'; } </script> </body> </html> HTML DOM onclick event supports All HTML elements, Except: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title> Comment More infoAdvertise with us Next Article HTML DOM onclick Event V Vijay Sirra Follow Improve Article Tags : Web Technologies HTML HTML-DOM Similar Reads HTML DOM ondblclick Event The HTML DOM ondblclick event occurs on a double click by the user. In HTML:<element ondblclick="myScript">HTML<!DOCTYPE html> <html> <body> <button id="demo" ondblclick="myFunction()"> Double-click </button> <script> function myFunction() { alert("Double cl 1 min read HTML DOM onselect Event The HTML DOM onselect event occurs when a user selects text within an element, like input fields or textareas. It allows developers to execute JavaScript code in response to text selection actions. Syntax: In HTML<element onselect="Script">In JavaScriptobject.onselect = function(){Script};In J 1 min read HTML DOM onfocus Event The HTML DOM onfocus event occurs when an element gets focused. The onfocus event is mostly used with <input>, <select>, and <a>. The onfocus event is the opposite of the onblur event. Syntax: In HTML:<element onfocus="myScript">In JavaScript:object.onfocus = function(){myScr 2 min read HTML | DOM ontoggle Event The ontoggle event in HTML DOM occurs when the <details> element user opens or closes by the user. The <details> tag is used for the content/information which is initially hidden but could be displayed if the user wishes to see it. Supported tags <details> Syntax: In HTML: <elem 1 min read HTML DOM onsubmit Event The onsubmit event in HTML DOM occurs after the submission of a form. The form tag supports this event. Syntax: In HTML: <element onsubmit="Script">In JavaScript: object.onsubmit = function(){myScript};In JavaScript, using the addEventListener() method: object.addEventListener("submit", myScri 2 min read Like