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

    MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
    MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3bfa9-2b01d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
    MySQL Errno : 1021
    Message : Disk full (/tmp/#sql-temptable-64f5-1b3bfa9-2b01d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
    Need Help?