tags:

views:

76

answers:

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

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

+5  A: 

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.

Jonathan Sampson
@Jonathan, what made you change this from your first example?
jeerose
Brevity. Using `.replaceWith()` was shorter.
Jonathan Sampson
+6  A: 

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.

CMS
Nice one. +1 for this.
jeerose
+1 I initially tried this, but I must have not loaded 1.4 into jsbin, or I wrote "content" instead. Either way, good work.
Jonathan Sampson
Thanks @jeerose and @Jonathan
CMS
Thank you all for the answers
Dee