String anchor() Method - Javascript String

Javascript examples for String:anchor


The anchor() method is used to create an HTML anchor.

This method returns the string embedded in the <a> tag, like this: <a name="anchorname">string</a>

Parameter Values

Parameter Description
name Required. The name of the anchor

Return Value:

A string embedded in the <a> tag

The following code shows how to Create an HTML anchor around a string:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<button onclick="myFunction()">Test</button>

function myFunction() {//  w  w  w .j a  v a 2s  . c  o m
    var txt = "test";
    txt.anchor("anchor link");


Related Tutorials