jQuery element creation w/ Attributes (v44)

Revision 44 of this benchmark created on


Description

I liked http://jsperf.com/jquery-element-creationyay/6 but the last test wasn't equivalent as it was not creating a JQUERY instance of the new element.

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery create
$('<div id="id" class="class">some Text</div>');
ready
jQuery create
$('<div/>').attr({
 id: 'id'
}).addClass('class').html('some Text');
ready
jQuery create with document.createElement
$(document.createElement('div')).attr({
 id: 'id'
}).addClass('class').html('some Text');
ready
jQuery >= 1.4 create
$('<div/>', {
 id: 'id',
 'class': 'class',
 html: 'some Text'
});
ready
create Element
var e = document.createElement('div');
e.id = 'id';
e.class = 'class';
e.innerHTML = 'some Text';

var $e = $(e);
ready

Revisions

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