With the string, jQuery has to parse it, to find the tagname and any
attributes. For a dozen elements it doesn't make any real difference,
but when you get to the hundreds or thousands of elements it's
significant:

100 elements:
String: 34ms
DOMElement: 5ms

1000 elements:
String: 339ms
DOMElement: 40ms

This in Firefox 3, Core 2 Duo 1.6ghz, using Firebug (code below).

cheers,
- ricardo

(function(){
var i=1001, r=i;
console.time('string');
while(--i){
 $('<div/>');
}
console.timeEnd('string');

i=r;
console.time('DOMEl');
while(--i){
  $(document.createElement('div'));
};
console.timeEnd('DOMEl');
})();

On Jan 14, 3:04 pm, thomasvsundert <thomas.vansund...@gmail.com>
wrote:
> Hi,
> the new documentation for jQuery 1.3 states that:
>
> "To create a span use $("<span/>"). As of jQuery 1.3 this syntax is
> completely equivalent to $(document.createElement("span"))."
>
> First of all, what does this mean? What was the difference before?
>
> My real question is, what is the performance penalty for using $("<div/
>
> >") vs $(document.createElement("div"))
>
> thanks,
> Thomas

Reply via email to