Defining a HTML template to append using JQuery

前端 未结 7 974
死守一世寂寞
死守一世寂寞 2020-11-29 14:48

I have got an array which I am looping through. Every time a condition is true, I want to append a copy of the HTML code below to a container element with some

相关标签:
7条回答
  • 2020-11-29 15:34

    Very good answer from DevWL about using the native HTML5 template element. To contribute to this good question from the OP I would like to add on how to use this template element using jQuery, for example:

    $($('template').html()).insertAfter( $('#somewhere_else') );
    

    The content of the template is not html, but just treated as data, so you need to wrap the content into a jQuery object to then access jQuery's methods.

    0 讨论(0)
提交回复
热议问题