Anchor text Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor


The text property sets or gets the text content of a link.

Set the text property with the following Values

sometext Sets the text content of a link

Return Value

A String, representing the text content of the link

The following code shows how to Return the text content of a link:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<p><a id="myAnchor" href="">Example link</a></p>

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

function myFunction() {/*from  w ww . j  a v a 2 s.c o  m*/
    var x = document.getElementById("myAnchor").text;


Related Tutorials