Skip to main content

Bug Tracker

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:

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 March 18, 2010 01:03AM UTC.
Change History (2)

Changed March 22, 2010 05:45PM UTC by furf comment:1

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.

Changed November 10, 2010 08:52PM UTC by addyosmani comment:2

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.