JavaScript anchor()Method
JavaScript String Object
Definition and Usage
The anchor() method is used to create an HTML anchor.
This method returns the string with <a> tags added, as shown below:
<a name="anchorname">string</a>
Syntax
string.anchor(name)
| Parameter | Description |
|---|---|
| name | Required. The name of the anchor |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the anchor() method.
Example
Example
Create an HTML anchor:
<script>
var txt = "Chapter 10";
txt.anchor("chap10");
alert(txt.anchor("chap10"));
</script>
var txt = "Chapter 10";
txt.anchor("chap10");
alert(txt.anchor("chap10"));
</script>
Try it Yourself »
JavaScript String Object Other Extensions