Skip to main content

Bug Tracker

Side navigation

#13429 closed bug (duplicate)

Opened February 10, 2013 09:34PM UTC

Closed February 10, 2013 09:45PM UTC

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

Reported by: jonathan.pasquier@gmail.com 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

Attachments (0)
Change History (3)

Changed February 10, 2013 09:41PM UTC by rwaldron comment:1

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

Changed February 10, 2013 09:44PM UTC by gibson042 comment:2

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.

Changed February 10, 2013 09:45PM UTC by gibson042 comment:3

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.