String.prototype.anchor()

  • Revision slug: JavaScript/Reference/Global_Objects/String/anchor
  • Revision title: anchor
  • Revision id: 87926
  • Created:
  • Creator: Maian
  • Is current revision? No
  • Comment /* Example: Using <code>anchor</code> */

Revision Content

Summary

Creates an HTML anchor that is used as a hypertext target.

Method of String
Implemented in: JavaScript 1.0, NES2.0

Syntax

anchor(nameAttribute)

Parameters

nameAttribute 
A string.

Description

Use the anchor method with the document.write or document.writeln methods to programmatically create and display an anchor in a document. Create the anchor with the anchor method, and then call write or writeln to display the anchor in a document. In server-side JavaScript, use the write function to display the anchor.

In the syntax, the text string represents the literal text that you want the user to see. The nameAttribute string represents the NAME attribute of the A tag.

Anchors created with the anchor method become elements in the document.anchors array.

Examples

Example: Using anchor

The following example code within an HTML script element:

var myString = "Table of Contents";
document.writeln(myString.anchor("contents_anchor"));

will output the following HTML:

<A NAME="contents_anchor">Table of Contents</A>

See Also

link

Revision Source

<p>
</p>
<h3 name="Summary"> Summary </h3>
<p>Creates an <a class="external" href="http://www.w3.org/TR/html401/struct/links.html#adef-name-A">HTML anchor</a> that is used as a hypertext target.
</p>
<table class="fullwidth-table">
<tbody><tr>
<td class="header" colspan="2">Method of <a href="en/Core_JavaScript_1.5_Reference/Objects/String">String</a></td>
</tr>
<tr>
<td>Implemented in:</td>
<td>JavaScript 1.0, NES2.0</td>
</tr>
</tbody></table>
<h3 name="Syntax"> Syntax </h3>
<p><code>
anchor(<i>nameAttribute</i>)
</code>
</p>
<h3 name="Parameters"> Parameters </h3>
<dl><dt> <code>nameAttribute</code> </dt><dd> A string.
</dd></dl>
<h3 name="Description"> Description </h3>
<p>Use the <code>anchor</code> method with the <code>document.write</code> or <code>document.writeln</code> methods to programmatically create and display an anchor in a document. Create the anchor with the <code>anchor</code> method, and then call <code>write</code> or <code>writeln</code> to display the anchor in a document. In server-side JavaScript, use the <code>write</code> function to display the anchor.
</p><p>In the syntax, the text string represents the literal text that you want the user to see. The <code>nameAttribute</code> string represents the <code>NAME</code> attribute of the A tag.
</p><p>Anchors created with the <code>anchor</code> method become elements in the <code>document.anchors</code> array.
</p>
<h3 name="Examples"> Examples </h3>
<h4 name="Example:_Using_anchor"> Example: Using <code>anchor</code> </h4>
<p>The following example code within an HTML <code>script</code> element:
</p>
<pre>var myString = "Table of Contents";
document.writeln(myString.anchor("contents_anchor"));
</pre>
<p>will output the following HTML:
</p>
<pre>&lt;A NAME="contents_anchor"&gt;Table of Contents&lt;/A&gt;
</pre>
<h3 name="See_Also"> See Also </h3>
<p><a href="en/Core_JavaScript_1.5_Reference/Objects/String/link">link</a>
</p>
Revert to this revision