How to create a link from a text using JavaScript?

To create a link, use the JavaScript link() method. This method creates an HTML hypertext link that requests another URL. The following is the syntax: hrefname )

Above, hrefname is any string that specifies the HREF of the <a> tag; it should be a valid URL.


You can try to run the following code to learn how to work with link() method in JavaScript −

Live Demo

      <title>JavaScript String link() Method</title>

         var str = new String("Simply Easy Learning");
         var URL = "";
         document.write( URL ));

Updated on: 15-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started