Javascript: best approach for displaying a single list item

What is the best approach?

  • adding several DOM elements to the parent node and setting all but one of them to "hidden" ( disply='none'). On demand, set the currently visible element to "hidden" and the other to "visible".

  • Just add one DOM element and change its attributes and contents on demand.

+3
source share
1 answer

Defined option 1. Chatting with the DOM is never a good idea. We just do it out of necessity.

The less you change the DOM, the better.

PS do not forget to cache your selectors ...

+4
source

All Articles