Bug Tracker

Opened 7 years ago

Closed 7 years ago

#13429 closed bug (duplicate)

jQuery(html) won't work if html start with a new line

Reported by: jonathan.pasquier@… Owned by:
Priority: undecided Milestone: None
Component: core Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:

Description

As of 1.9.1, it is not possible to create DOM element from HTML code with the jQuery function if the HTML code starts with a \n

This code won't work (although it used to with 1.8.3):

$("\n<p>Hi</p>").appendTo(aDiv);

But this one will!

aDiv.append("\n<p>Hi</p>");

(here is a JSFiddle with a test case: http://jsfiddle.net/H2nWM/)

I understand that this is a consequence of #11290, but maybe jQuery(html) detection should take into account every whitespace characters before the first < and not only whitespace?

I'm working with FF 18 but was able to reproduce the bug on Chromium 23.

Thanks,

Jonathan

Change History (3)

comment:1 Changed 7 years ago by Rick Waldron

Resolution: notabug
Status: newclosed

maybe jQuery(html) detection should take into account every whitespace characters before the first < and not only whitespace?

Did you mean "not only space"?

Anyway, read the 1.9 upgrade: http://jquery.com/upgrade-guide/1.9/#jquery-htmlstring-versus-jquery-selectorstring

comment:2 Changed 7 years ago by gibson042

Component: unfiledcore
Resolution: notabug
Status: closedreopened

Use jQuery.parseHTML if you want to keep the leading whitespace as a text node; otherwise jQuery.trim the input before passing it to jQuery. Even if we do relax our requirements in the future, your code will be more clear and robust.

comment:3 Changed 7 years ago by gibson042

Resolution: duplicate
Status: reopenedclosed

Duplicate of #13223.
Use jQuery.parseHTML if you want to keep the leading whitespace as a text node; otherwise jQuery.trim the input before passing it to jQuery. Even if we do relax our requirements in the future, your code will be more clear and robust.

Note: See TracTickets for help on using tickets.