XHTML Events

 

When you go to a website, you can click on text, images, and links, move your mouse over things, and so on. These are examples of events in JavaScript.

We can write our event handlers in either JavaScript or VBScript, and we can use the value of the event tag attribute to point to these event handlers. The events in XHTML 1.0 are the same as those in the HTML 4.01 specification.

The <body> and <frameset> Level Events

There are only two attributes that can be used to run any JavaScript or VBScript code when a document-level event happens.

AttributeValueDescription
onloadScriptWhen an XHTML file loads, a script runs.
onunloadScript
When an XHTML document stops loading, a script is run.

The <form> Level Events

There are six attributes that happen whenever any event at the form level happens.

AttributeValueDescription
onchangeScriptWhen the element changes, the code is run.
onsubmitScript
It is carried out when the form is sent.

onresetScriptWhenever the form is cleared, it is run.
onselectScriptWhenever the element is chosen, the code is run.
onblurScriptWhen the element loses attention, it is activated.
onfocusScriptWhen the element receives focus, the code is run.

Keyboard Events

There are three things that can happen when you use the keyboard. The keyboard events are not allowed in the base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title elements.

AttributeValueDescription
onkeydownScriptOnce the user presses and releases the corresponding key on the keyboard, this action is carried out.
onkeypressScriptWhen the finger is lifted off the keyboard, something occurs.
onkeyupScriptThis is executed when the user release the keyboard button.

Mouse Events

There are some mouse-driven events that run when the mouse touches an HTML tag. These events are not allowed in the base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title elements.

AttributeValueDescription
onclickScriptA single click of the mouse to execute code.
ondblclickScriptA mouse double-click to execute code..
onmousedownScriptwhen mouse button is pressed to execute code..
onmousemoveScriptWhen mouse pointer moves to execute code..
onmouseoutScriptWhen mouse pointer moves out of an element to execute code..
onmouseoverScriptWhen mouse pointer moves over an element to execute code..
onmouseupScriptWhen mouse button is released to execute code..
Related Article
XHTML Tutorial

The XHTML tutorial explains both the basics and more advanced ideas about XHTML. Our XHTML tutorial is made for both Read more

About XHTML

  EXtensible HyperText Markup Language is what XHTML is short for. It is a mix of the HTML language and Read more

Doctypes in XHTML

  Descriptions of Document Types come in three flavours (DTDs). The XHTML Transitional standard is the most user-friendly and widespread. Read more

Attributes of XHTML

  Some XHTML attributes are the same for all XHTML tags and go with them. There are three different kinds Read more

Syntax of XHTML

The syntax of XHTML is substantially similar to that of HTML, and all valid HTML components are likewise valid in Read more

How to Disable a Link Using CSS Styling Links

How to visually hide an element with CSS? What is the purpose of the hidden attribute in HTML? How to Read more