lundi 29 décembre 2014

Javascript: Need run twice Node.removeChild() for node removed


I trying to remove li node but I have to run twice deleteNode(); for node be removed.


I need remove li tag and the img tag inside...





window.onload = function() {
deleteNode();
deleteNode();
}


function deleteNode() {
var node;
node = document.getElementById("sliders");
node.removeChild(node.firstChild);
}



<body>
<div id="jsSlider">
<div class="slider-wrapper">
<ul id="sliders">
<li>
<img src="img/sample-1.jpg" alt="" />
</li>
<li>
<img src="img/sample-2.jpg" alt="" />
</li>
<li>
<img src="img/sample-3.jpg" alt="" />
</li>
</ul>
</div>
</div>

<div id="prueba"></div>
</body>



This is pure javascript I cannot use jQuery or other js framwork? How can remove the li tag only run Node.removeChild() one time?

Thanks in avanced!





Aucun commentaire:

Enregistrer un commentaire