On Sep 25, 2009, at 11:56 AM, Bertilo Wennergren wrote:


Karl Swedberg wrote:

Internally, jQuery determines whether to use document.createElement by checking the string against a regular expression:
   rsingleTag = /^<(\w+)\s*\/?>$/
Unless I'm missing something, allowing for both syntaxes would be trivial. Just change the regex to something like this (untested):
   rsingleTag = /^<(\w+)\s*\/?>(<\/\w+>)?$/
I think I'll recommend that.

That seems to work.

But event then, in the following case '<span/>' is still being
converted to '<span></span>' (and then passed to innerHTML):

 var html = '<span/>';
 $("#div").html(html);

--
Bertilo Wennergren <http://bertilow.com>


Right. I'm pretty sure that's because the html string is handled differently if it's an argument of a DOM manipulation method (e.g. .html('<span/') ) as opposed to an argument of the jQuery function (e.g. $('<span/') ).

If I recall correctly, all of the DOM manipulation methods are run through the same set of functions before performing their specific task. While changing '<span></span>' might not be necessary for .html(), it is for .wrap(), for example.

--Karl

Reply via email to