JavaScript link() method explained

The JavaScript String object has a built-in method called link() that you can use to display a string type data as a hypertext.

You need to pass the web address you want to be added to the href attribute as the argument to the link() method.

The following code example will transform the text "Go to Google" as an anchor element <a> to navigate toward "":

const str = "Go to Google";
const url ="");
console.log(url); // <a href="">Go to Google</a>

The implementation of the link() method varies between different browsers, but I’ve tested the method on the latest Chrome and Safari version. The method also works in the NodeJS environment, so you can use it there as well. Just be sure to test the result first before you use the method.

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.