JavaScript string.anchor() Method
Below is the example of the string.anchor() Method.
- Example 1:
<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)
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.
<!DOCTYPE html><html><body> <script> var str="GeeksForGeeks"; window.alert(str.anchor("anchorname")); </script></body></html> |
Output:

Example 2:
var str="GeeksForGeeks";console.log(str.anchor("anchorname")); |
Output:
<a name="anchorname">GeeksForGeeks</a>
Supported Browser:
- Internet Explorer
- Firefox
- Google Chrome
- Safari
- Opera


