How to insert a large block of HTML in JavaScript?

后端 未结 7 876
悲哀的现实
悲哀的现实 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 19:18

    If I understand correctly, you're looking for a multi-line representation, for readability? You want something like a here-string in other languages. Javascript can come close with this:

    var x =
        "
    \ \

    \ some text \

    \
    ";

提交回复
热议问题