a Creating a Hyperlink or Anchor

<a> Creating a Hyperlink or Anchor

The <a> element creates a hyperlink (use the href attribute) or anchor (use the id and/or the deprecated name attribute for browsers that need to use name , such as Netscape Navigator). This element is supported in XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, and XHTML 1.1. Here are this element's attributes:

  • accesskey Assigns a keyboard access key to the hyperlink. (XHTML 1.0 Strict, XHTML 1.0 Transitional.)

  • charset Indicates the character encoding of the hyperlink's target. Set this to Request for Comments (RFC) 2045 language character set string. The default value is ISO-8859-1. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • class Gives the style class of the element. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • coords Sets the coordinate values (in pixels) appropriate to the corresponding shape attribute to define a region of an image for image maps. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • dir Sets the direction of text that doesn't have an inherent direction in which you should read it, called directionally neutral text. You can set this attribute to ltr , for left-to-right text, or rtl , for right-to-left text. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • href Holds the target URI of the hyperlink. You must assign a value to either this attribute or the id attribute. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • hreflang Gives the base language of the target indicated in the href attribute. Set this to RFC 1766 values. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • id Refer to the element; set this attribute to a unique identifier. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • lang Specifies the base language used in the element. Only applies when the document is interpreted as HTML. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • name Available in the three XHTML 1.0 DTDs, but deprecated; not available in the XHTML 1.1 DTD (use id instead). Gives the anchor a name, which may be used as the target of a hyperlink. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset.)

  • rel Specifies the relationship described by the hyperlink. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • rev Same as the rel attribute, but the syntax works in the reverse direction. For example, a link from A to B with rel="X" signifies the same relationship as a link from B to A with rev="X" . (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • shape Specifies the type of region for mapping in an <area> element. This is used with the coords attribute. Possible values include rect (the default), circ , circle , POLY , and polygon . (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • style Inline style indicating how to render the element. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • tabindex Specifies the tab sequence of hyperlinks in the page for keyboard navigation. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset.)

  • target Indicates the named frame that serves as the target of the hyperlink. (XHTML 1.0 Transitional, XHTML 1.0 Frameset.)

  • title Contains the title of the element (which might be displayed in ToolTips). (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • type Specifies the Multipurpose Internet Mail Extensions (MIME) type of the target given in the href attribute. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • xml:lang Specifies the base language for the element when the document is interpreted as an XML document. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

This element supports these XHTML events: onclick , ondblclick , onfocus , onblur , onmousedown , onmouseup , onmouseover , onmousemove , onmouseout , onkeypress , onkeydown , and onkeyup .

New href Attribute

In XHTML 2.0, any element can be a hyperlink with the new href attribute, which is a part of the new XHTML 2.0 Common Attribute Collection.

The <a> element is a big part of what makes the Web work. You use this element to create hyperlinks and anchors (an anchor can serve as the target of a hyperlink). In this element, you must set either the href attribute to set the target URI of a hyperlink, or the id attribute to create an anchor. Here's an example using href , specifying the W3C site as the target of a hyperlink:

Listing ch17_03.html
 <?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">     <head>         <title>             Using the &lt;a&gt; Element         </title>     </head>     <body>        <center>            <h1>             Using the &lt;a&gt; Element            </h1>            Want to learn more about XHTML? Go to:  <a href="http://w3c.org">W3C</a>.  </center>     </body> </html> 

You can see the results of this XHTML in Figure 17-2. As is standard in HTML browsers, the hyperlink appears as underlined text (largely because the browser thinks this is standard HTML). You can also use graphical hyperlinks if you enclose an <img> element in the <a> element.

Figure 17-2. Displaying a hyperlink.

graphics/17fig02.gif



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net