Bug Tracker

Opened 13 years ago

Closed 12 years ago

#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:
Blocked by: Blocking:


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.


Leading and trailing text fragments are currently dropped when using jQuery() to create DOM elements.


$("this <em>doesn't work</em> as expected");



which renders as:

<em>doesn't work</em>

After my fix:

$("this <strong>works</strong> as expected");


[<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>');


[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.


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.


Attachments (1)

core.js (20.3 KB) - added by furf 13 years ago.

Download all attachments as: .zip

Change History (3)

Changed 13 years ago by furf

Attachment: core.js added

comment:1 Changed 13 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 12 years ago by addyosmani

Priority: undecided
Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.