Bajagain Binod
Bajagain Binod

Reputation: 21

How can I get the text content of an anchor tag?

I am using an anchor tag and have to access its content in jQuery. I have to access the 'text' from this. I have known about $("#AnchorID").attr("href") or something else but is there any way to grab the value ('text') of it?

<a href="">text</a>

Upvotes: 2

Views: 540

Answers (1)

Adil
Adil

Reputation: 148110

Use $("#AnchorID").text(),

Live Demo

<a id="AnchorID" href="">text</a>

To get the text

textOfAnchor = $("#AnchorID").text(); 

To change the text

$("#AnchorID").text("new text");

To get the html

htmlOfAnchor = $("#AnchorID").html(); 

Upvotes: 6

Related Questions