JQuery: Build HTML in 'memory' rather than DOM

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

    var sample =
        $('
    ') .append( $('
    ') .addClass('testing-attributes') .text('testing')) .html();

    Which creates:

    testing

提交回复
热议问题