JS - Remove a tag without deleting content

前端 未结 8 1086
渐次进展
渐次进展 2021-01-04 04:09

I am wondering if it is possible to remove a tag but leave the content in tact? For example, is it possible to remove the SPAN tag but leave SPAN\'s content there?



        
8条回答
  •  走了就别回头了
    2021-01-04 04:47

    There are several ways to do it. Jquery is the most easy way:

    //grab and store inner span html
    var content = $('p span').html;
    //"Re"set inner p html
    $('p').html(content);
    

    Javascript can do the same using element.replace. (I don't remember the regex to do the replace in one stroke, but this is the easy way)

    paragraphElement.replace("", "");
    paragraphElement.replace("", "");
    

提交回复
热议问题