Open In App

JavaScript string anchor() Method

Last Updated : 15 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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.

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>

Supported Browsers:

  • Chrome 1
  • Edge 12
  • Firefox 1
  • Opera 3
  • Safari 1

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy