Creating complex elements (v4)

Revision 4 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="hiddenContainer" style="display:none;">
  <div>
    <table>
      <tr>
        <td>
          1
        </td>
        <td>
          2
        </td>
      </tr>
    </table>
  </div>
</div>

Teardown


    $("#outputContainer").html("");
  

Test runner

Ready to run.

Testing in
TestOps/sec
Passing full html string to jQuery
var elements = "<div><table><tr><td>1</td><td>2</td></tr></table></div>";
$("body").append($(elements));
ready
Create elements by hand but still using jQuery
function create() {
  return $("<div>").append($("<table>").append('tr').append('td'));
}
$("body").append(create());
ready
Using innerHTML
var elements = "<div><table><tr><td>1</td><td>2</td></tr></table></div>";
var div = document.createElement('div')
div.id = 'mycustomdiv'
document.getElementsByTagName('body')[0].appendChild(div);
div.innerHTML = elements;
ready
hidden div + jquery
$("#outputContainer").html($("#hiddenContainer").html());
ready
hidden div moved as element
$("#hiddenContainer").appendTo($("#outputContainer"));
$("#hiddenContainer").show();
ready
appendchild with jquery element
$("#outputContainer").appendChild($("#hiddenContainer"));
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.