JQuery: Build HTML in 'memory' rather than DOM

前端 未结 7 982
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 21:43

Is there a way to \'pre-build\' a snippet of HTML before adding it to the DOM?

For example:

$mysnippet.append(\"

hello

\"); $mysni
7条回答
  •  醉话见心
    2020-11-29 22:27

    Yes pretty much exactly how you have done it

    Some extension of this...

    $('
    ').attr('id', 'yourid').addClass('yourclass').append().append()...

    and then finally

    .appendTo($("#parentid"));
    

提交回复
热议问题