html-to-element vs document.createElement

Edit on GitHub

Setup

var wrapper = document.createElement('div');
function htmlToElement(html){
wrapper.innerHTML = html
return wrapper.firstChild;
}

Tests

  • html-to-element

    var element = htmlToElement('<div><p>test</p></div>');
  • document.createElement

    var element = document.createElement('div');
    var p= document.createElement('p');
    p.innerHTML = 'test';
    element.appendChild(p);