Best way to create large static DOM elements in JavaScript?

前端 未结 5 1565
野性不改
野性不改 2020-12-23 10:13

I have many elements that one of my JS widgets needs to create and add to the DOM often. They never change.

So one option would be to store the HTML itself as a stri

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-23 10:28

    You answered yourself already.

    EDIT: deleted wrong sample.

    Or there is another option, you can put the HTML right into the current html inside of hidden div like this:

    
    

    And then in jquery, you can read it:

    var elements = $("#hiddenContainer").html()
    

提交回复
热议问题