Event attributes bind event handlers directly in HTML, executing JavaScript when a specific event occurs. They can be used on all HTML elements.
Window / Document Events
Event Attributes
Description
onload
Fires when the element finishes loading.
onunload
Fires when the page unloads.
onresize
Fires when the window is resized.
onscroll
Fires when an element or the page is scrolled.
onerror
Fires when a resource fails to load.
Form Events
Event Attributes
Description
onsubmit
Fires when a form is submitted.
onreset
Fires when a form is reset.
onchange
Fires when an element's value changes and it loses focus.
oninput
Fires immediately when the element's value changes.
onfocus
Fires when the element gains focus.
onblur
Fires when the element loses focus.
onselect
Fires when text is selected in a text field.
Keyboard Events
Event Attributes
Description
onkeydown
Fires when a key is pressed down.
onkeyup
Fires when a key is released.
onkeypress
Fires when a key is pressed and released (deprecated).
Mouse Events
Event Attributes
Description
onclick
Fires when the element is clicked.
ondblclick
Fires when the element is double-clicked.
onmousedown
Fires when a mouse button is pressed down on the element.
onmouseup
Fires when a mouse button is released on the element.
onmousemove
Fires when the mouse moves over the element.
onmouseover
Fires when the mouse enters the element or its children.
onmouseout
Fires when the mouse leaves the element or its children.
onwheel
Fires when the mouse wheel is scrolled over the element.
oncontextmenu
Fires when the context menu is opened (right-click).
Drag Events
Event Attributes
Description
ondrag
Fires while an element is being dragged.
ondrop
Fires when a dragged element is dropped onto a target.
Clipboard Events
Event Attributes
Description
oncopy
Fires when content is copied.
oncut
Fires when content is cut.
onpaste
Fires when content is pasted.
Web-Tutorial Tech Team
A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.