Element removeChild Method - Remove a <li> element with id="myLI" from its parent element - Javascript DOM

Javascript examples for DOM:Element removeChild

Description

Element removeChild Method - Remove a <li> element with id="myLI" from its parent element

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<ul><li>Coffee</li><li id="myLI">Tea</li><li>Milk</li></ul>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from w  w  w  .  j a  va 2 s .c  om*/
    var item = document.getElementById("myLI");
    item.parentNode.removeChild(item);
}
</script>

</body>
</html>

Related Tutorials