JQuery: Build HTML in 'memory' rather than DOM

前端 未结 7 981
被撕碎了的回忆
被撕碎了的回忆 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:25

    Sure, just build them as a string:

    $mysnippet = "

    hello

    "; $mysnippet = $mysnippet + "

    world

    "; $("destination").append($mysnippet);

提交回复
热议问题