innerHTML vs createElement() and appendChild()

JavaScript performance comparison

Revision 3 of this test case created by jbdemonte

Info

Compares the performance of adding elements to DOM by using strings and innerHTML and creating DOMElement objects and appending them with appendChild().

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
innerHTML
var parent = document.createElement("div");
parent.innerHTML = '<div class="test"><p>This is a test</p></div>';
pending…
createElement() and appendChild()
var parent = document.createElement("div");

var div = document.createElement('div');
div.className = 'test';

var p = document.createElement('p');
p.innerText = 'This is a test';

div.appendChild(p);
parent.appendChild(div);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment