by Dinesh Thakur Category: Javascript String

The JavaScript Anchor is a string function that can be accessed using dot operator with string variable. It transforms the specified text into hypertext.

The JavaScript Anchor object is a place in a document that is the target of a hypertext link. It is the property of the document object. The JavaScript Anchor() method takes a parameter that will be the name attribute for the named anchor. Basically, it creates an HTML tag set with the following syntax:

<a name=" locationOrURL "> anchorName </a>

Where locationOrURL refers to a URL or destination anchor. anchorName indicates the anchor name that is the target for a hypertext.  For example, take a look at this code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
" ">

<html xmlns="" xml:lang="en" lang="en">
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>JavaScript Anchor() method </title>
  <h1 style="color: blue">JavaScript anchor() method</h1> <hr />
  <script type="text/javascript">
  var locationOrURL = "";
  var anchorName = locationOrURL.anchor("Computer Notes");

Here, you assign a string literal to the variable locationOrURL. You then call the anchor() method with a parameter of “Computer Notes” from the string literal. The result is assigned to the anchorName variable. The value of the anchorName variable is then written on the page. JavaScript Anchor()  method returns the string embedded in the <a> tag, like this:

JavaScript anchor()

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.