Skip to content

Instantly share code, notes, and snippets.

@maximgatilin
Last active August 20, 2020 02:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximgatilin/5fa5d59a42e5aaeb328278565bba3c65 to your computer and use it in GitHub Desktop.
Save maximgatilin/5fa5d59a42e5aaeb328278565bba3c65 to your computer and use it in GitHub Desktop.
Document fragment with jQuery
var documentFragment = $(document.createDocumentFragment());
for (var i = 0; i < 5; ++i) {
var span = $('<span>' + i + '</span>');
documentFragment.append(span);
}
console.info(documentFragment);
$('#result').append(documentFragment);
// Более легкий способ
var htmlStr = '';
ajaxResult.items.forEach(function(item) {
// Построим строку
htmlStr += '<li>' + item.text + '</li>';
});
// Комбинация элементов списка через innerHTML
document.querySelector('ul').innerHTML = htmlStr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment