Ticket #6303 (closed enhancement: invalid)
support for leading/trailing fragments when using jQuery() to create DOM elements
| Reported by: | furf | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | 1.4.3 |
| Component: | core | Version: | 1.4.2 |
| Keywords: | jquery core DOM init | Cc: | |
| Blocking: | Blocked by: |
Description
I added support for including leading/trailing text fragments as TextNodes when using jQuery() to create DOM elements.
The fix is available in my Github fork. I've also issued a pull request.
http://github.com/furf/jquery/blob/master/src/core.js
Leading and trailing text fragments are currently dropped when using jQuery() to create DOM elements.
Currently:
$("this <em>doesn't work</em> as expected");
returns:
[em]
which renders as:
<em>doesn't work</em>
After my fix:
$("this <strong>works</strong> as expected");
returns:
[<TextNode textContent="this ">, strong, <TextNode textContent=" as expected">]
which renders as:
this <strong>works</strong> as expected
It seems strange that:
$('<em>this</em> and <em>that</em>');
returns:
[em, <TextNode textContent=" and ">, em]
and this:
$('some of <em>this</em> and <em>that</em>');
ALSO returns:
[em, <TextNode textContent=" and ">, em]
The patch was written in support of my $.template plugin (a Resig micro-templating variant). Loose text fragments were being omitted which required all templates to contain a wrapping DOM element whether it was needed or not.
http://github.com/furf/jquery-template
Since it looks like the discussion about templating in the jQuery core is heating up, this added feature may be worth inclusion. Otherwise, you may have to document the fact that templates require a DOM node (or nodes) at the extremities of the HTML.
Hope it helps.
furf
Attachments
Change History
comment:1 Changed 3 years ago by furf
After further experimentation, realized why this is in the doc!
html A string defining a single, standalone, HTML element (e.g. <div/> or <div></div>).
TextNodes in the collection will break certain functionality, like .hide()
Guess you can forget this one for now and I'll look for alternative fix to my template engine.
comment:2 Changed 3 years ago by addyosmani
- Priority set to undecided
- Status changed from new to closed
- Resolution set to invalid
As the original ticket submitter has noted correctly that we specify documentation explaining the behavior responsible for their ticket and they have also confirmed this is no longer an issue jQuery core is causing due to error, I'm closing this ticket.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

