Loading lesson path
Concept visual
Start at both ends
HTML has the ability to let events trigger actions in a browser, like starting a JavaScript when a user clicks on an element.To learn more about programming events, please visit our JavaScript tutorial.
Below are the global event attributes that can be added to HTML elements to define event actions.Formula
Events triggered for the window object (applies to the < body > tag):Script to be run after the document is printed onbeforeprint script Script to be run before the document is printed onbeforeunload script Script to be run when the document is about to be unloaded onerror script Script to be run when an error occurs onhashchange script Script to be run when there has been changes to the anchor part of the a URL onload script Fires after the page is finished loading onmessage script Script to be run when the message is triggered onoffline script Script to be run when the browser starts to work offline ononline script Script to be run when the browser starts to work online onpagehide script Script to be run when a user navigates away from a page onpageshow script Script to be run when a user navigates to a page onpopstate script Script to be run when the window's history changes onresize script Fires when the browser window is resized onstorage script Script to be run when a Web Storage area is updated onunload script Fires once a page has unloaded (or the browser window has been closed)
Events triggered by actions inside a HTML form (applies to almost all HTML elements, but is most used in form elements):
Fires the moment that the element loses focus onchange script Fires the moment when the value of the element is changed oncontextmenu script Script to be run when a context menu is triggered onfocus script Fires the moment when the element gets focus oninput script Script to be run when an element gets user input oninvalid script Script to be run when an element is invalid onreset script Fires when the Reset button in a form is clicked onsearch script Fires when the user writes something in a search field (for <input="search">) onselect script Fires after some text has been selected in an element onsubmit script
Fires when a user is pressing a key onkeypress script Fires when a user presses a key onkeyup script
Fires on a mouse click on the element ondblclick script
Formula
Fires on a mouse double - click on the element onmousedown scriptFires when a mouse button is pressed down on an element onmousemove script Fires when the mouse pointer is moving while it is over an element onmouseout script Fires when the mouse pointer moves out of an element onmouseover script Fires when the mouse pointer moves over an element onmouseup script Fires when a mouse button is released over an element onmousewheel script Deprecated.
Fires when the mouse wheel rolls up or down over an element
Script to be run when an element is dragged ondragend script Script to be run at the end of a drag operation ondragenter script Script to be run when an element has been dragged to a valid drop target ondragleave script Script to be run when an element leaves a valid drop target ondragover script Script to be run when an element is being dragged over a valid drop target ondragstart script Script to be run at the start of a drag operation ondrop script Script to be run when dragged element is being dropped onscroll script Script to be run when an element's scrollbar is being scrolled