Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript string.anchor() Method

  • Difficulty Level : Medium
  • Last Updated : 05 Oct, 2021

Below is the example of the string.anchor() Method.

  • Example 1:

            var str="GFG"; 
  • Output:

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

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

<a name=anchorname>string</a>




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

JavaScript Version: JavaScript1.0

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

<!DOCTYPE html>
        var str="GeeksForGeeks";


Example 2:

var str="GeeksForGeeks";


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

Supported Browsers:

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!