The anchor
method is defined in the String
class in JS and encloses the String
instance on which it is invoked with the anchor tag (e.g. <a>string_here</a>
).
anchor(name);
name
: a string that is to be set as the name
attribute for the anchor tag.name
attribute of the anchor tag is also set, as specified by the argument name
.let str = 'Hello World';console.log(str.anchor('hello'));
In the example above, the anchor
method is called on an instance of String
, the str
variable. The method call results in the text stored in str
to be enclosed in the <a>
tag. Additionally, the name
argument has the value hello
, so the name
attribute of the anchor tag is also set to hello
.
Free Resources