JavaScript tutorial:
anchor method

 

Applies to: String Object

The anchor method places an HTML anchor with a NAME attribute around specified text in the object.

Syntax

strVariable.anchor(anchorstring)
"String Literal".anchor(anchorstring)

The anchorstring argument is text you want to place in the NAME attribute of an HTML anchor.

Return value

None

Example

Call the anchor method to create a named anchor out of a String object. The following example demonstrates how the anchor method accomplishes this:

<HTML>
<HEAD>
<SCRIPT language="javaScript" >
function anchorTag()
{
var strVariable = "This is an anchor" ;
strVariable = strVariable.anchor("This is an anchor 1");
return strVariable;
}
</SCRIPT>
</HEAD>
<P>See how it work in htm
<BODY>
<SCRIPT LANGUAGE= "JAVASCRIPT">
document.write(anchorTag());
</SCRIPT>
</BODY>
</HTML>

To run the code, paste it into JavaScript Editor, save as htm file format and click the Show Internal View button.

See also: link method, String Object methods, String Object properties