This method creates an HTML anchor that is used as a hypertext target.
Its syntax is as follows −
string.anchor( anchorname )
anchorname − Defines a name for the anchor.
Returns the string having the anchor tag.
Try the following example.
<html> <head> <title>JavaScript String anchor() Method</title> </head> <body> <script type="text/javascript"> var str = new String("Hello world"); alert(str.anchor( "myanchor" )); </script> </body> </html>
<a name="myanchor">Hello world</a>