On 28/08/12 09:26, Daniel Friesen wrote:
jQuery does special case attribute-less $(
'<div />' ) but this is a
performance enhancement. The fact that $( '<div>' ) does not break in
IE7/IE8 is an unintentional side effect of jQuery's lazy support of
special cases like $( '<img>' ) where the tag is self closing and the
browser will not require a /.
The performance special case supports both <div> and <div/>:
rsingleTag = /^<(\w+)\s*\/?>$/,
...
ret = rsingleTag.exec( selector );
if ( ret ) {
selector = [ doc.createElement( ret[1] ) ];
I think that we should use that special case, and then extend the
resulting elements with attr() rather than hitting the innerHTML case.
When you specify longer HTML fragments as strings, they tend to get
polluted with user input, leading to XSS.
But it's important to establish conventions which lead the developer
down a path where they're less likely to run into trouble, even if
they do try to take a few shortcuts. So let's add the slash.
(There is one important case where it's good to use innerHTML: when
there are thousands of elements to create in a batch.)
-- Tim Starling