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 (binary) DOM tree structure. If the '/' is missing there it simply means the code showing the DOM tree as text leaves out the '/' - which doesn't have any representation in the DOM tree anyway, it only belongs in the source code from which the tree was created. Regards, Michael On Jan 15, 4:39 am, RWF <mgor...@gmail.com> wrote: > 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=$("<img/>"); > image.alt="hello world"; > > $("#maindiv").append(image); > > The result was a single <img> without a / like this: > <div id=maindiv><img></div> > > Am I misunderstanding something? > > On Jan 14, 3:13 pm, Ricardo Tomasi <ricardob...@gmail.com> wrote: > > > 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"))