jQuery element creation

JavaScript performance comparison

Revision 26 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var $h = function(tag) {
  var div = document.createElement(tag);
  div.id = 'id';
  div.className = 'class';
  return div;
}
var $g = function(tag) {
  var div = document.createElement(tag);
  div.id = 'id';
  div.classList.add('class');
  return div;
}
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
With trailing slash
$('<div/>').attr({ id : 'id', class : 'class' });
pending…
Without trailing slash
$('<div>').attr({ id : 'id', class : 'class' });
pending…
Opening and closing tags
$('<div></div>').attr({ id : 'id', class : 'class' });
pending…
document.createElement
var div = document.createElement('div');
div.id = 'id';
div.className = 'class';

$(div);
pending…
with alias
$h('div');
pending…
HTML5 classList
var div = document.createElement('div');
div.id = 'id';
div.classList.add('class');

$(div);
pending…
HTML5 classList with alias
$g('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