javascript add/remove list items
HTML DOM removeChild() MethodElement Object Show ExampleRemove the first
var list = document.getElementById("myList"); // Get the
Before removing:
After removing:
More "Try it Yourself" examples below. Definition and UsageThe removeChild() method removes a specified child node of the specified element. Returns the removed node as a Node object, or null if the node does not exist. Note: The removed child node is no longer part of the DOM. However, with the reference returned by this method, it is possible to insert the removed child to an element at a later time (See "More Examples"). Tip: Use the appendChild() or insertBefore() method to insert the removed node into the same document. To insert it to another document, use the document.adoptNode() or document.importNode() method. Browser Support
Syntax
Parameter Values
Technical Details
More ExamplesExampleFind out if a list has any child nodes. If so, remove its first child node (index 0):
// Get the
Before removing:
After removing:
ExampleRemove all child nodes of a list:
// Get the
Before removing:
After removing: ExampleRemove a
var item = document.getElementById("myLI");
Before removing:
After removing:
ExampleRemove a
var item = document.getElementById("myLI");
Try it Yourself »
ExampleRemove a element from its parent and insert it to an
var child = document.getElementById("mySpan");
Try it Yourself »
Element Object |