Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Global Attributes

Although most tag attributes tend to be unique to the tag, some are almost universal and usable with any tag. Table 3.1 summarizes these attributes, showing which tags do take the attributes and how each attribute is used.

Table 3.1 Global HTML Attributes

Attribute Purpose Used With

CLASS Space-separated list of classes of the tag All tags but <BASE>, <BASEFONT>, <HEAD>, <HTML>, <META>, <PARAM>, <SCRIPT>, <STYLE>, and <TITLE>.
DIR Direction for weak or neutral text All tags but <APPLET>, <BASE>, <BASEFONT>, <BDO>, <BR>, <FRAME>, <FRAMESET>, <HR>, <IFRAME>, <PARAM>, and <SCRIPT>.
ID Unique, document-wide identifier All tags but <BASE>, <HEAD>, <HTML>, <META>, <SCRIPT>, <STYLE>, and <TITLE>.
LANG Specifies document language context All tags but <APPLET>, <BASE>, <BASEFONT>, <BR>, <FRAME>, <FRAMESET>, <HR>, <IFRAME>, <PARAM>, and <SCRIPT>.
STYLE Binds style information to the tag All tags but <BASE>, <BASEFONT>, <HEAD>, <HTML>, <META>, <PARAM>, <SCRIPT>, <STYLE>, and <TITLE>.
TITLE Advisory title All tags but <BASE>, <BASEFONT>, <HEAD>, <HTML>, <META>, <PARAM>, <SCRIPT>, <STYLE>, and <TITLE>.

The global attribute you’ll probably use most often is the STYLE attribute, which is used to assign style information to a tag. To color a level 2 heading red, for example, you could use the HTML:

<H2 STYLE=”color: red”>Red Heading</H2>

The ID attribute is also useful when you need to have a unique identifier for a tag. This situation comes into play when you write scripts to support dynamic HTML documents because you frequently want to change the properties of some marked-up text. To do this, you need to be able to address the tag that marks up the text via JavaScript, JScript, or VBScript, and the best way to do that is to give the tag a unique name. Then it becomes fairly simple to address the tag via the browser’s object model.

See “Introduction to Dynamic HTML,” p. 581.

LANG can be helpful in situations where you are marking up content in multiple languages. The value of LANG gives browsers a “heads-up” as to what language is being used. LANG is usually set equal to a two-character language code that denotes the language being used. For example, “fr” denotes French; “de” denotes German, and so on. In cases where variants on a language exist, you’ll see expanded language codes, such as “en-US” for English spoken in the United States or “en-Br” for English spoken in Britain.

DIR refers to the directionality—left-to-right or right-to-left—of text when it cannot otherwise be deduced from the context of the document. DIR can take on values of LTR (left-to-right) or RTL (right-to-left).

The TITLE attribute enables you to specify descriptive text to associate with the tag. This information may be helpful to nonvisual browsers, such as those that generate speech or Braille output.

Finally, the CLASS attribute enables you to create different classes of the same tag. For example, you might have:

<A HREF=”xrefs.html” CLASS=”cross-reference”> ... </A>
<A HREF=”defns.html” CLASS=”definition”> ... </A>
<A HREF=”biblio.html” CLASS=”bibliography”> ... </A>

This creates three classes of the <A> tag. After these classes are established, you can reference them elsewhere in your document. One popular application of this is in a style sheet:

A.cross-reference {color: navy}
A.definition {color: yellow}
A.bibliography {color: fuschia}

The style information above would color cross-reference links navy blue, definition links yellow, and bibliography links fuschia.

Event Handlers

The HTML 4.0 recommendation also allows for several event handlers that can be used to trigger the execution of script code embedded in an HTML document. Each event handler is tied to a specific event that can occur during a person’s use of a browser. When a user submits a form, for example, you can capture that event and launch a field validation script using the onsubmit event handler:

<FORM ACTION=”register.cgi” METHOD=”POST” onsubmit=”validate();”>

• For the specifics on writing scripts for your HTML documents, see “Introduction to JavaScripting,” p. 439 or “Active Server Pages and VBScript,” p. 835.

Thus, when a user clicks the Submit button, the scripted function named “validate” fires and checks the data the user is submitting for appropriate formatting, content, or other validation checks.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.