The difference between creating element (createElement) and concatenating string (innerHtml) in JS

I would like to ask, what is the difference between creating html through document.createElement ("li") and through innerHtml ="

  • "?

    also, if I created the element through createElement, can I empty it directly through innerHtml ="";?

    for example, insert li? into ul

    Mar.15,2022

      The LI element created by
    1. document.createElement ('li') also needs to be manually inserted into the UL or it will not take effect in the DOM
    2. innerHtml ='
    3. 'is generated and inserted into DOM without the need for you to manually insert
    4. also, if I created the element through createElement, can I empty it directly through innerHtml ='';?
      Yes, but you have to insert it into DOM first

    1, no difference
    2, you can


    to create append elements it is recommended to use DocumentFragments;
    Why always append DOM elements using DocumentFragments

    Menu