JavaScript get parent element and write holder div for siblings

前端 未结 3 1781
小蘑菇
小蘑菇 2020-12-16 13:08

I have the following structure:

Content here
Content here&l
3条回答
  •  余生分开走
    2020-12-16 13:28

    Seeing as this has to be JavaScript (and not jQuery) and you can only indentify the child1 by id you could do something as crude as this:

    var child1 = document.getElementById("child1"),
        parent = child1.parentNode,
        contents = parent.innerHTML ;
        parent.innerHTML = '
    ' + contents + '
    ';

    Hope this helps...

提交回复
热议问题