Opened 10 years ago
Closed 10 years ago
#13429 closed bug (duplicate)
jQuery(html) won't work if html start with a new line
Reported by: | 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 10 years ago by
Resolution: | → notabug |
---|---|
Status: | new → closed |
comment:2 Changed 10 years ago by
Component: | unfiled → core |
---|---|
Resolution: | notabug |
Status: | closed → reopened |
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 10 years ago by
Resolution: | → duplicate |
---|---|
Status: | reopened → closed |
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.
Did you mean "not only space"?
Anyway, read the 1.9 upgrade: http://jquery.com/upgrade-guide/1.9/#jquery-htmlstring-versus-jquery-selectorstring