Saturday, November 16, 2024
Google search engine
HomeLanguagesJavascriptJavaScript string anchor() Method

JavaScript string anchor() Method

The Javascript anchor() method creates an anchor element that is used as a hypertext target that means when you use the anchor method in JavaScript the anchor method returns <a> elements with string and also returns “anchorname” as the value of “name” attribute like this:

<a name=anchorname>string</a>

Syntax:

 string.anchor(anchorname)

Note: This method has been DEPRECATED and is no longer recommended.

Parameters: This method accepts a single parameter.

  • anchorname: The name of the anchor.

Return Value: The anchor() method returns the string with <a> element.

JavaScript Version: JavaScript1.0

Below are examples of the string.anchor() Method.

Example 1: This example shows the basic use of the anchor tag in Javascript.

Javascript




let str = "GFG";
console.log(str.anchor("anchorname"));


Output:

<a name="anchorname">GFG</a>

Example 2: This example shows you how to use anchor() method.

Javascript




let str = "GeeksForGeeks";
console.log(str.anchor("anchorname"));


Output:

 <a name="anchorname">GeeksForGeeks</a>

We have a complete list of Javascript string methods, to check those please go through the Javascript String Complete Reference article.

Supported Browsers:

  • Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Opera 3 and above
  • Safari 1 and above
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments