Skip to content
Related Articles

Related Articles

JavaScript string.anchor() Method

View Discussion
Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 01 Jun, 2022
View Discussion
Improve Article
Save Article

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

  • Example 1: 

HTML




<script>
        var str="GFG";
        window.alert(str.anchor("anchorname"));
</script>

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>

Syntax:

 string.anchor(anchorname)

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

Parameters:

  • 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.

HTML




<!DOCTYPE html>
<html>
<body>
  <script>
        var str="GeeksForGeeks";
        window.alert(str.anchor("anchorname"));
  </script>
</body>
</html>

Output:

 

Example 2: 

javascript




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

Output:

<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!