Add or remove child elements
Element instances have array-like characteristics. Adding or removing nodes only requires using the array manipulation methods. When using push, unshift, pop, shift, and splice methods, the internal $ method initialization is automatically executed, so you can directly fill in the specific element strings or objects.
Similarly, you can also use other array methods, such as forEach, map, some, etc.
Please note: do not add or remove child elements on elements with template syntax.
push
Append child elements from the end.
- I am 1
- I am 2
- I am 3
unshift
Add child elements at the beginning of the array.
- I am 1
- I am 2
- I am 3
pop
Remove child elements from the end.
- I am 1
- I am 2
- I am 3
shift
Remove child 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 array's splice method.
- I am 1
- I am 2
- I am 3