Created
January 11, 2017 01:59
-
-
Save avshabanov/7d5adcb08e621300be3860cc2caaacb0 to your computer and use it in GitHub Desktop.
Append HTML String as DOM part
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
// NOTE: two approaches are possible here, one uses jquery abstractions (and works on pretty old browsers), | |
// while the other uses insertAdjacentHTML, the standard API in all the modern browsers (and old IEs too!). | |
// | |
// First approach (jquery way): | |
const $element = $($.parseHTML(htmlString)); | |
$element.appendTo($container); | |
// Other approach (HTML, works on modern browsers): | |
$container.each(function () { this.insertAdjacentHTML('beforeend', htmlString); }); | |
// Links: | |
// https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML | |
// https://msdn.microsoft.com/en-us/library/ms536452(v=vs.85).aspx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment