Last active
August 20, 2020 02:12
-
-
Save maximgatilin/5fa5d59a42e5aaeb328278565bba3c65 to your computer and use it in GitHub Desktop.
Document fragment with jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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