Open In App

What is anchor() Method in JavaScript ?

The anchor() method in JavaScript is a string method used to create an HTML anchor element (<a>) with the specified text (the string itself) as the visible content, and a URL specified as the method’s argument as the href attribute of the anchor element.

Syntax:

string.anchor(name)

Example: Here, the anchor() method is called on the str string with the URL "https://example.com" as its argument. This creates an HTML anchor element (<a>) with the text "Click here" as its content and the URL "https://example.com" as its href attribute value. The resulting anchor element is then assigned to the anchorTag variable.




const str = "Click here";
 
console.log(anchorTag);

Output
<a name="https://www.geeksforgeeks.org/javascript-typedarray-reverse-method/amp/">Click here</a>

Note:

Article Tags :