Remove element with jQuery but leave text

前端 未结 3 926
既然无缘
既然无缘 2020-12-13 13:28

I\'ve got some html that looks like this:

red text some more text blue text
相关标签:
3条回答
  • 2020-12-13 14:04

    Wouldn't a simple $('#my-div').text ($('#my-div').text ()) suffice, without resorting to unwrapping?

    0 讨论(0)
  • 2020-12-13 14:04
    $(mydiv).html($(mydiv).text()) 
    

    should do the trick.

    0 讨论(0)
  • 2020-12-13 14:19

    jQuery 1.4+

    You don't want to unwrap the span, you want to unwrap its contents:

    $("span").contents().unwrap();
    

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

    jQuery 1.2+

    For earlier versions of jQuery, you could do the following:

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

    Online Demo: http://jsbin.com/iyigi/40/edit

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