单击删除按钮删除内容(DIV)

时间:2013-07-27 22:28:48

标签: javascript html

当我点击左下角的删除图标时,我试图删除里面的div和内容。我怎么能这样做?单击X时,问题的内容和div将消失。

这是代码。

<li class="question" id="question2">
    <div class="question-header curves dense-shadows">
        What color is the sky? 
    </div>
    <div class="question-content dense-shadows">
        <ol type="A">
            <li><input type="radio" id="q2a1" name="question2" /> Red</li>
            <li><input type="radio" id="q2a2" name="question2" /> Green</li>
            <li><input type="radio" id="q2a3" name="question2" /> Blue</li>
            <li><input type="radio" id="q2a4" name="question2" /> Brown</li>
        </ol>
        <div style="text-align:right">

            <a href="#" class="delete"><span style="margin-left:5px;"><img src="images/deletebutton.png" 
                onmouseover="this.src='images/deletebuttonhover.png'" onmouseout="this.src='images/deletebutton.png'" title="Delete" alt="delete"/></span></a>
        </div>
    </div>
</li>

2 个答案:

答案 0 :(得分:1)

<a href="#" class="delete" onclick="document.body.removeChild(document.getElementById('question2'))">

答案 1 :(得分:0)

尝试使用

  

yourDivToBeDeleted.innerHTML = “”;