with appendChild
and removeChild
, respectively
https://developer.mozilla.org/en/DOM/element.appendChild
https://developer.mozilla.org/En/DOM/Node.removeChild
you could also use
- innerHTML to append/remove elements (in some circustances can be more suitable, especially for large node insertion)
- createDocumentFragment really useful for appending DOM structures with sub-nested elements
2
solved How to Create and Remove HTML elements with Javascript dynamically [closed]