JS - Remove a tag without deleting content

前端 未结 8 1169
渐次进展
渐次进展 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:21

    If it’s the only child span inside the parent, you could do something like this:

    HTML:

    The weather is sure sunny today

    ;

    JavaScript:

    parent = document.querySelector('.parent');
    parent.innerHTML = parent.innerText;
    

    So just replace the HTML of the element with its text.

提交回复
热议问题