JavaScript/Removing elements

HTML pages and DOM objects are hierarchically structured. Every element and attribute belongs to exactly one parent. To delete an element or attribute, first, you must locate the parent element. The remove operation can be done on this object.

Remove elements
Elements are removed with the  function. To delete the  element from the   element in the following example

the JavaScript code is ...

... and the remaining HTML structure will be

Children of children
If an element is removed, all of its children are removed as well. By this, you can remove huge parts of the DOM with one command if they have a common root. E.g., remove a complete list:

The JavaScript fragment removes the  element as well as all   elements.

parentNode
To remove an element, you need to know its parent element. If you can locate only the child, but for some reason, not the parent, the child's property  shows you the way.

Remove attributes
Attributes are removed with the  function. To delete the  attribute from the   element in the following example

the JavaScript code is:

The element itself, including the text of the link, keeps alive, but you cannot navigate anymore.