Javascript DOM HTML UL remove <LI> element by id

Description

Javascript DOM HTML UL remove <LI> element by id

View in separate window

<!DOCTYPE html>
<html>
<body>

<ul><li>CSS</li><li id="myLI">Tea</li><li>Java</li></ul>

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

<script>
function myFunction() {/* w ww . j a  v a2 s .c o m*/
  var item = document.getElementById("myLI");
  item.parentNode.removeChild(item);
}
</script>

</body>
</html>



PreviousNext

Related