从子HTML链接到div中嵌入的父HTML

时间:2013-12-13 13:27:42

标签: javascript html parent-child

我在div中使用父标记中的id标记调用了一部分子HTML文件。我想创建一个按钮来清理子内容并返回到该div内的父级。对于图形来说,JS代码对此是什么?

1 个答案:

答案 0 :(得分:0)

假设你的html是:

<div class='parent'>
    <div class='innerParent'>
     <input type='button' id='removeChildContent'>
     <div class='child'>
     </div>
    </div>
</div>

所以,使用jQuery,您可以清理子内容,如下所示:

$(function()
{
 $('#removeChildContent').click(function()
 {
  $(this).siblings().not(':first').remove();//removes the child elements of inner parent, except this button
 })
})