Skip to content
Related Articles

Related Articles

Improve Article
JavaScript string.anchor() Method
  • Difficulty Level : Basic
  • Last Updated : 04 Sep, 2020

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 Browser:

  • Internet Explorer
  • Firefox
  • Google Chrome
  • Safari
  • Opera

My Personal Notes arrow_drop_up
Recommended Articles
Page :