Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js add html element

function create(htmlStr) {
    var frag = document.createDocumentFragment(),
        temp = document.createElement('div');
    temp.innerHTML = htmlStr;
    while (temp.firstChild) {
        frag.appendChild(temp.firstChild);
    }
    return frag;
}
e = `<p>your html here </p>`

var fragment = create(e);
// You can use native DOM methods to insert the fragment:
document.body.insertBefore(fragment, document.body.childNodes[0]);
Source by www.tutorialspoint.com #
 
PREVIOUS NEXT
Tagged: #js #add #html #element
ADD COMMENT
Topic
Name
2+5 =