Dee
Dee

Reputation: 1403

Replace a link with it's text with jQuery

<a href="#">TEST</a>

I want to remove the anchors and keep the Text i.e TEST

Upvotes: 18

Views: 6256

Answers (2)

Sampson
Sampson

Reputation: 268324

If you want to remove the link and leave the text:

$("a").replaceWith(function(){ return $(this).text() });​

Online Demo: http://jsbin.com/aguki/edit

If you're using jQuery 1.4+, CMS provided an even shorter answer.

Upvotes: 6

Christian C. Salvad&#243;
Christian C. Salvad&#243;

Reputation: 827198

You could also use the new $.unwrap method (jQuery 1.4+) applied to the contents of the anchor:

​$('a').contents().unwrap();​​

Check an example here.

Upvotes: 32

Related Questions