內所有的HTML元素我有這樣的HTML:刪除DIV
<div class="row" id="conditional-one">
<div class="large-12 columns">
<h3><?php echo $arrayStage_rule_one_title?></h3>
<p>
<?php echo $arrayStage_rule_one_description?>
</p>
<ul style="list-style-type:disc; margin-left:10px;">
<?php echo $arrayStage_rule_one_description_bullets?>
</ul>
<h3><?php echo $arrayStage_rule_one_bullets_title?></h3>
<br>
<ul style="list-style-type:disc; margin-left:10px;">
<?php echo $html_rule_one_bullets?>
</ul>
</div>
</div>
而且我想,如果這個條件滿足時刪除div中所有的HTML元素與id="conditional-one"
:
// select div by ID
var conditionalOne = document.getElementById("conditional-one");
// Assign PHP strings to JavaScript variables
var conditionalOneText = '<?php echo $place_bullet_one?>';
if (conditionalOneText !== "1" || conditionalOneText !== "2") {
conditionalOne.removeChild(conditionalOne.firstChild);
} else {
// do nothing
}
當前ConditionalOneText爲== 3,但conditional-one
內的div未被擦除。如果條件滿足,任何人都可以幫我清除conditional-one
div中的所有HTML元素嗎?
什麼是被抹去,如果有的話? –
如果你想使用removeChild,你必須循環你的firstchild節點,如下所示:while(conditionalOne.firstChild)conditionalOne.removeChild(conditionalOne.firstChild); } – darron614