Skip to main content

Bug Tracker

Side navigation

#7133 closed bug (invalid)

Opened October 08, 2010 02:39PM UTC

Closed October 08, 2010 08:57PM UTC

Adding an array to html() causes an error

Reported by: Motty Owned by:
Priority: low Milestone: 1.4.3
Component: manipulation Version: 1.4.2
Keywords: .html() array Cc:
Blocked by: Blocking:

I know this is not the intended purpose of .html(), but I think it needs to at least not crash when the function is presented with an array. Using .text() will fail gracefully, but not .html().

I posted a demo of it here (

 var testing = ['hello','world'];
Attachments (0)
Change History (2)

Changed October 08, 2010 03:43PM UTC by addyosmani comment:1

component: coremanipulation
keywords: → .html() array
need: ReviewPatch
priority: undecidedlow

Although I haven't had any browsers crash in testing the submitted bug , I did get the following FireBug console output when running the test case in FF:

uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMDocumentFragment.appendChild]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: :: anonymous :: line 4500" data: no]

Using .html(testing.join(' ')) is a valid workaround (as you correctly mentioned) but we should probably be addressing this in the core (at least ensuring it fails gracefully in the same way that .text() does).

Looking between lines 4219 and 4225:

in this case we're falling back on this.empty().append( value );. Were we to consider adding an additional case similar to .text() where we fall back on

this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( value ) );

or some variant, this may be preferable compared to an error output.

We probably also need to address what is the expected behavior when appending an array through .html() in this manner. I'm not a fan of .createTextNode() as the fallback,but it would be interesting to hear that others might think would be a more appropriate solution.

Flagging for further review and patch.

Changed October 08, 2010 08:57PM UTC by snover comment:2

resolution: → invalid
status: newclosed

Nowhere is it stated that passing an array to .html and .text is valid. The only reason it works in .text is because it checks to see if the passed content is not an object (typeof Array is object). So all you are really doing when you call .text and pass an array is calling the getter method—it doesn’t actually work.