Side navigation
#6303 closed enhancement (invalid)
Opened March 18, 2010 01:02AM UTC
Closed November 10, 2010 08:52PM UTC
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: | |
Blocked by: | Blocking: |
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 (1)
Change History (2)
Changed March 22, 2010 05:45PM UTC by comment:1
Changed November 10, 2010 08:52PM UTC by comment:2
priority: | → undecided |
---|---|
resolution: | → invalid |
status: | new → closed |
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.
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.