Skip to main content

Bug Tracker

Side navigation

#8348 closed bug (invalid)

Opened February 22, 2011 01:46PM UTC

Closed July 12, 2011 02:12PM UTC

jQuery.fn.text on a textNode

Reported by: Owned by:
Priority: low Milestone:
Component: manipulation Version: 1.5
Keywords: Cc:
Blocked by: Blocking:

When calling


The text is set to "foo" instead of "bar". One would expect that you can set the text on a textNode using .text()

see jsFiddle:

The problem lies here.

if ( typeof text !== "object" && text !== undefined ) {
    return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );

An assumption was made that you can append a text node to a text node. Which is invalid because textNodes can't have children.

One possible solution is checking for this.nodeType === 3 and using elem.nodeValue = text.

An alternative would be using as seen here:

I've only tested nodeValue in internet explorer and firefox.

Attachments (0)
Change History (2)

Changed February 24, 2011 03:25PM UTC by rwaldron comment:1

component: unfiledmanipulation
priority: undecidedlow
status: newopen

Changed July 12, 2011 02:12PM UTC by dmethvin comment:2

resolution: → invalid
status: openclosed

Text and comment nodes have only limited support; in most cases we attempt to remove them before performing any operations (for example after a .contents() method). Don't attempt to wrap a text node in a jQuery object.