Side navigation
#12047 closed bug (wontfix)
Opened July 10, 2012 07:17AM UTC
Closed July 12, 2012 03:06PM UTC
Last modified July 12, 2012 04:54PM UTC
body.removeChild( container ); can cause an error
Reported by: | Ian Yang | Owned by: | Ian Yang |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | support | Version: | 1.7.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
An answer of a question on stackoverflow shows that jQuery adds some elements (the outmost one is container
) to do some tests (line 1537 in the un-minified version):
// Run tests that need a body at doc ready jQuery(function() { var container, outer, inner, table, td, offsetSupport, ...
And at line 1654 jQuery wants to remove that test element with:
body.removeChild( container );
However, as addressed in the question, by using the DOMNodeInserted
event, all contents of body
can be wrapped inside another element before jQuery can remove that test element, causing body.removeChild( container );
to fail because the container
isn't a child element of body
anymore.
So the suggestion is to change line 1654 into:
jQuery( container ).remove();
Attachments (0)
Change History (8)
Changed July 10, 2012 01:51PM UTC by comment:1
component: | unfiled → support |
---|---|
priority: | undecided → low |
resolution: | → wontfix |
status: | new → closed |
Changed July 12, 2012 12:51PM UTC by comment:3
resolution: | wontfix |
---|---|
status: | closed → reopened |
Changed July 12, 2012 12:52PM UTC by comment:4
owner: | → Ian Yang |
---|---|
status: | reopened → pending |
Can you provide a test case on jsFiddle that reproduces the issue, not using the deprecated DOMNodeInserted?
Changed July 12, 2012 01:37PM UTC by comment:5
Replying to [comment:4 dmethvin]:
Can you provide a test case on jsFiddle that reproduces the issue, not using the deprecated DOMNodeInserted?
Here is the test case on jsFiddle. Please use the Firebug on Firefox 13 to see the error. And please click on the "Run" button to run it again if you don't see the error. On jsFiddle, the chance of this happening is 50%.
Note: the technique used in the test case is inspired by this article.
Changed July 12, 2012 03:06PM UTC by comment:6
resolution: | → wontfix |
---|---|
status: | pending → closed |
Support loads before most other modules, in particular manipulation, so that line can execute before .remove
is defined. And more importantly, we're just not prepared to tolerate external manipulation of our internal-use elements.
Changed July 12, 2012 04:06PM UTC by comment:7
We could get around the error sans jQuery with container.parentNode.removeChild(container)
but I don't think that resolves the issue -- it only hides it. If you are wrapping the HTML we use to do feature detects it is going to affect the jQuery.support
outcomes, and cause jQuery to misbehave in strange ways down the road. The workaround would be do not attach your DOMNodeInserted
handler until document ready, since we attach our ready handler for support checks first.
Changed July 12, 2012 04:54PM UTC by comment:8
Thanks for the advise anyway.
Btw, I have no intention of manipulating anyone's internal-use elements. I won't even know they exist if they didn't cause my browser to throw the error.
DOMNodeInserted is deprecated and should no longer be used.
http://www.w3.org/TR/DOM-Level-3-Events/#event-type-DOMNodeInserted