Replace a link with it's text with jQuery

后端 未结 2 387
半阙折子戏
半阙折子戏 2020-12-10 11:27
TEST

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

相关标签:
2条回答
  • 2020-12-10 12:03

    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.

    0 讨论(0)
  • 2020-12-10 12:18

    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.

    0 讨论(0)
提交回复
热议问题