Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace a link with it's text with jQuery

Tags:

jquery

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

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

like image 379
Dee Avatar asked Feb 19 '10 04:02

Dee


2 Answers

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.

like image 141
Christian C. Salvadó Avatar answered Nov 14 '22 03:11

Christian C. Salvadó


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.

like image 32
Sampson Avatar answered Nov 14 '22 04:11

Sampson