Check out the test: http://jsperf.com/wrap-with-jq
var s = $('<span />').text('my span'); s.wrap('<div id="myWrap" class="myClass"></div>').parent();
8 073 ops / sec
87% slower
s.wrap($('<div />', { 'id': 'myWrap', 'class': 'myClass' }).parent());
72,955 ops / sec
Is there a reason this is much faster when creating a new element with jQuery? I would suggest that this was slower due to the need to wrap an element using jQuery.
In fact, this is not so much. There is a typo in your test ...
s.wrap($('<div />', { 'id': 'myWrap', 'class': 'myClass' // move `parent` call outside... })).parent();
, , parent, ([]), s.wrap, s , dom, .
[]
s.wrap
http://jsperf.com/wrap-with-jq/3
5,118 4,149 / jq
. , , , .
, jQuery, JS-, , div, , documentFragment, HTML-, . , , HTML.
: . , HTML , , , , .
, , , .