#10075 closed bug (invalid)
$(" ... html ...") strips leading and trailing text nodes in HTML string
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.6.2 |
Keywords: | neededdocs | Cc: | |
Blocked by: | Blocking: |
Description
Hi,
I stumbled about this when trying to use $() with an HTML string that contains multiple top-level nodes and starts with a text node:
- $("1<br/>2<br/>3")
- Expected result: ["1", <br>, "2", <br>, "3"]
- Observed result: [<br>, "2", <br>]
Additional observations:
The nodes are created as expected if the HTML string starts with "<" and ends with ">", even if the characters are converted to text nodes.
- $("1<br/>2<br/>3 >") returns (incorrectly):
- [<br>, "2", <br>, "3 >"]
- $("< 1<br/>2<br/>3") returns (incorrectly):
- ["< 1", <br>, "2", <br>]
- $("< 1<br/>2<br/>3 >") returns (correctly):
- ["< 1", <br>, "2", <br>, "3 >"]
- $("1<br/>2<br/>3<!-- -->") returns (incorrectly):
- [<br>, "2", <br>, "3", (comment)]
- $("<!-- -->1<br/>2<br/>3") returns (incorrectly):
- [(comment), "1", <br>, "2", <br>]
- $("<!-- -->1<br/>2<br/>3<!-- -->") returns (correctly):
- [(comment), "1", <br>, "2", <br>, "3", (comment)]
(The last is what I'm using as a workaround right now.)
Tested on:
- Firefox 6.0
- Google Chrome 13.0.782.112 m
OS:
- Windows 7 x64 SP1
Regards, Philipp Serafin
Change History (2)
comment:1 Changed 11 years ago by
Keywords: | needsdocs added |
---|---|
Resolution: | → invalid |
Status: | new → closed |
comment:2 Changed 11 years ago by
Keywords: | neededdocs added; needsdocs removed |
---|
I've updated the docs for this here: http://api.jquery.com/jQuery/
Note: See
TracTickets for help on using
tickets.
jQuery isn't intended to process text nodes as if they were DOM elements. Most methods save a few like
.content()
remove or ignore them if they are in a jQuery collection.I've marked the ticket for a documentation review, but the behavior is correct.