onclick Attribute


 

Where to use the onclick Attribute

onclick is a Common Attribute from the Events Attribute Collection and is of Type Script.

It may be used on most elements in the Element Index - all except: base, bdo, br, head, html, meta, param, script, style, title.


Description

The onclick attribute is a common attribute which may be used on most elements to specify script to be executed when the element is clicked, i.e. there is a "mousedown" followed by a "mouseup" over the same element.

For an element which would ordinarily perform an action when clicked (e.g. input type="submit") this default action can be prevented (in script-enabled user agents) by returning false from its onclick handler. Note that form submission (or reset) can also be prevented by returning false from the onsubmit (or onreset) handlers of the form element itself.

See also the onmouseup, onmousedown and ondblclick attributes.

If you use this attribute (or any attributes of Type Script) the MIME type of the scripting language used should always be provided in a Content-Script-Type HTTP header.

It is good practice not to use these attributes, however, and instead to include external scripts (via script elements) which add any handlers unobtrusively. This makes code more self-contained and also the XHTML is easier to maintain if it doesn't contain any events attributes.


Page Footer & Copyright

Copyright © Sally Maughan 2005-2009 (Page last updated on 16 May 2009)

*Valid XHTML 1.1 - hosted by *Openstrike

Content based on the W3C Working Draft: *XHTML 1.1 and Recommendation: *XHTML Modularisation 1.1.

W3C, XHTML, XML, HTML, CSS and MathML are *Trademarks of the W3C (*MIT, *ERCIM, *Keio) with which the site's author has no connection.


Up, Next & Previous Links

Your Location

Home > XHTML 1.1 Home > XHTML 1.1 Indexes > Attribute Index (XHTML 1.1) > onclick Attribute (XHTML 1.1)