Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I know there is a solution with Jquery called unwrap, but I am writing "raw" JavaScript. I didn't find any solution without jQuery.

I'd like to remove a div like so:

<div><div id="mydiv">Important text here</div></div>

After removal of "mydiv":

<div>Important text here</div>

What should I do, I'd like to know the theory.

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
342 views
Welcome To Ask or Share your Answers For Others

1 Answer

shouldn't this line work

 document.getElementById("mydiv").outerHTML = document.getElementById("mydiv").innerHTML

See this JSBin Example (inspect the element)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...