This JavaScript tutorial explains how to use the string approach referred to as anchor() with syntax and examples.
Description
In JavaScript, anchor() is a string approach that is used to create the HTML factor (or anchor). Because the anchor() technique is a method of the String object, it should be invoked via a specific occasion of the String class.
Syntax
In JavaScript, the syntax for the anchor() method is:
string.anchor(anchor_name);
Parameters or Arguments
anchor_name It is a string cost that will be used as the title attribute for the element.
Returns
The anchor() approach returns a string containing an element. The price of string is enclosed in and tags as the hyperlink text and the fee of the anchor_name parameter is used as the name attribute for the element.
Note
The anchor() technique does now not alternate the price of the unique string.
Example
Let’s take a appear at an example of how to use the anchor() technique in JavaScript.
For example:
var totn_string = 'TechOnTheNet';
console.log(totn_string.anchor('website'));
In this example, we have declared a variable called totn_string that is assigned the string cost of ‘TechOnTheNet’. We have then invoked the anchor() method of the totn_string variable to return a string that consists of the HTML anchor.
We have written the output of the anchor() technique to the web browser console log, for demonstration purposes, to exhibit what the anchor() method returns.
The following will be output to the net browser console log:
<a name="website">TechOnTheNet</a>
As you can see, the anchor() technique created a string that carries an element. The cost of the totn_string variable (which is ‘TechOnTheNet’) is enclosed within the and tags. The string value of ‘website’ that used to be exceeded into the anchor() method as a parameter is used as the title attribute for the element.
Leave a Review