Add or remove child elements
Element instances behave like arrays; nodes can be added or removed with the usual array methods. When using push, unshift, pop, shift, or splice, the internal $ method is automatically invoked for initialization, so you can pass element strings or objects directly.
Likewise, you can use other array methods such as forEach, map, some, and so on.
Please note: Do not add or remove child elements on elements with template syntax.
push
Add child element at the end
- I am 1
- I am 2
- I am 3
unshift
Add a child element to the beginning of the array.
- I am 1
- I am 2
- I am 3
pop
Delete child elements from the end.
- I am 1
- I am 2
- I am 3
shift
Remove sub-elements from the beginning of the array.
- I am 1
- I am 2
- I am 3
splice
You can delete or replace existing child elements, or add new child elements. Its usage is similar to the splice method of arrays.
- I am 1
- I am 2
- I am 3