You also made a little mistake:

var image=$("<img/>");
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 out, it doesn't make
any difference. There is no such a thing as a 'syntax error' in the
DOM.

- ricardo

On Jan 15, 1: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"))
>
> > > thanks,
> > > Thomas

Reply via email to