Like I have mentioned the documentFragment
is like an “Array” so you can push anything (appending child) to it based on your condition rest is removed.
Where you can read more what it is and how it can be used but I believe there are videos on YT about this.