[jQuery] Re: Performance penalty for creating dom element from a string?

2009-01-15 Thread Ricardo Tomasi
You also made a little mistake: var image=$(""); image.alt="hello world"; 'image' is a jQuery object, not the image element. That should be image.attr('alt',"hello world"); when you have empty elements without any properties firebug shows them without the closing tag, but as Michael pointed ou

[jQuery] Re: Performance penalty for creating dom element from a string?

2009-01-15 Thread michael.hasenst...@googlemail.com
You confuse the text representation of the DOM tree with HTML source code. Single tags in XHTML must have the '/'. However, if you insert a tag using Javascript you are not writing XHTML!!! So what you see e.g. in Firebug is NOT XHTML source code, it is a CUSTOM (arbitrary) representation of the

[jQuery] Re: Performance penalty for creating dom element from a string?

2009-01-14 Thread James Van Dyke
is a tag which doesn't require an ending tag. is another as is . The W3C validator will actually warn you if you end tags like that, though it's not a big deal. When jQuery creates the HTML, I believe the code is injected into an empty element and jQuery sees what the browser made of the stri

[jQuery] Re: Performance penalty for creating dom element from a string?

2009-01-14 Thread RWF
This also confused me. I tried creating the element as the1.3 docs show (as noted in the OP) and then appending it to a div and it did not generate a closing tag. This is what I did: var image=$(""); image.alt="hello world"; $("#maindiv").append(image); The result was a single without a / like

[jQuery] Re: Performance penalty for creating dom element from a string?

2009-01-14 Thread Ricardo Tomasi
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 DOMElemen