I found edge cases in IE where my code was magically fixed using $("<div></div>") instead of $("<div>") . I always do this out of paranoia.
At some point, I'm sure the jQuery docs indicate that you should close all your tags. This no longer applies to 1.6, but if you are using 1.3.2 or 1.4.2, you can close them to be safe.
Although, if you look at the source code, I would be tempted that for simple tags it is completely safe. Donβt be afraid that for complex tags or tags with attributes, the source uses .innerHTML , so I highly recommend that you pass correctly closed tags.
A source
var rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/; ... // If a single string is passed in and it a single tag // just do a createElement and skip the rest ret = rsingleTag.exec(selector); if (ret) { if (jQuery.isPlainObject(context)) { selector = [document.createElement(ret[1])]; jQuery.fn.attr.call(selector, context, true); } else { selector = [doc.createElement(ret[1])]; } } else { ret = jQuery.buildFragment([match[1]], [doc]); selector = (ret.cacheable ? jQuery.clone(ret.fragment) : ret.fragment).childNodes; }
In this case, with $("<div>") you find that ret[1] is a "div", so it calls document.createElement("div") .
Raynos
source share