String.link()

JavaScript1.0+, JScript1.0+ NES2+, Nav2+, IE3+, Opera3+ Syntax

							string.link(URL)

Description

The link() method will convert the string it is called on to an instance of the <a> tag, setting the HREF attribute to the URL that is passed.

Example

Listing 6.244 creates an instance of the String object and uses the document.write() method to write the tag to the page. The results of running this script will be the following:

<a href="http://www.purejavascript.com">The online book!</a>
Listing 6.244 Using the link() Method of the String Object
 <script language="JavaScript"> <!–– Hide // Create an instance of the String object var myString = new String("The online book!"); // Write the string to the page after invoking the link() ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.