How to insert a large block of HTML in JavaScript?

后端 未结 7 843
悲哀的现实
悲哀的现实 2020-12-07 18:50

If I have a block of HTML with many tags, how do insert it in JavaScript?

var div = document.createElement(\'div\');
div.setAttribute(\'class\', \'post block         


        
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-07 18:58

    The easiest way to insert html blocks is to use template strings (backticks). It will also allow you to insert dynamic content via ${...}:

    document.getElementById("log-menu").innerHTML = `
                 
                   ${data.user.email}
                
                
        `
    

提交回复
热议问题