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
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
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
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
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
5 matches
Mail list logo