'removeChild()' Example : removeChild « Node Operation « JavaScript DHTML






'removeChild()' Example

    
<html>
<body>
<script language="JavaScript">
function function1() {
    var m = "New Element";
    var n = document.createElement("li");
    n.appendChild(document.createTextNode(m));
    document.getElementById("myList").appendChild(n); 
} 
function function2() {
    myList.removeChild(myList.lastChild);
}
</script>
<ul id="myList">
   <li>1</li>
   <li>2</li>
   <li>3</li>
   <li>4</li>
   <li>5</li>
   <li>6</li>
   <li>7</li>
   <li>8</li>
   <li>9</li>
</ul>
<input type="button" value="Add list item" onClick="function1();">
<input type="button" value="Remove added items" onClick="function2();">
</body>
</html>

    
      
      








Related examples in the same category