What is the better approach?
-
adding multiple DOM elements to a parent node and setting all of them but one to “hidden” (
disply='none'). On demand set the currently visible element to “hidden” and another one to “visible”. -
Just add one DOM element and on demand change its attributes and content.
Definitely option 1. Messing around with the DOM is never a good idea. We just all do it out of necessity.
The less you change the DOM, the better.
P.S. remember to cache your selectors…