onfocus Attribute


 

Where to use the onfocus Attribute


Description

The onfocus attribute specifies script to be executed when the element gains focus, for example when tabbed to.

See also the onblur attribute.

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.

Note: In many browsers, label elements cannot be tabbed to and never receive focus (any focus is merely passed on to the relevant form control) so the script in the onfocus attribute is never executed in these browsers.


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) > onfocus Attribute (XHTML 1.1)