Skip to main content

Bug Tracker

Side navigation

#4554 closed bug (invalid)

Opened April 17, 2009 10:34AM UTC

Closed October 02, 2009 02:04AM UTC

INVALID_NODE_TYPE_ERR in Safari when using query context that not yet in the DOM

Reported by: snobo Owned by:
Priority: major Milestone: 1.4
Component: core Version: 1.3.2
Keywords: safari dom query exception Cc:
Blocked by: Blocking:
Description

As reported at:

http://groups.google.com/group/jquery-en/browse_thread/thread/1150ccc5548a7de8/1ba7855df1b062e8

COPY OF THE ORIGINAL POST:

I've stumbled upon a wicked problem, which appears only in 1.3.2

(works ok in 1.3.1, 1.3.0 and 1.2.6), and only in Safari (3.2.2 on

Windows) (works ok in FF2/3, IE6/7, Opera). To cut a long story short,

here's the test case:

http://tmp.ahlers.com/test/safari-132.html

My application employs FlexiGrid, so I've isolated the chunk of code

to a bare minimum that reproduces the error.

var sDiv = document.createElement('div');

sDiv.className = 'sDiv';

$(sDiv).append("<div class='sDiv2'>Quick Search <input type='text'

name='q' /> <select name='qtype'><option selected='selected'

value='port'>Port</option></select> <input type='button'

value='Clear' /></div>");

$('#output3').append(

$('input[name=q],select[name=qtype]',sDiv).map( function(){ return

this.name } ).get().join(', ')

);

$('#form .bDiv').after(sDiv);

So, the query $('input[name=q],select[name=qtype]',sDiv) crashes

jQuery 1.3.2 on the line #2118:

aRange.selectNode(a);

with the error "INVALID_NODE_TYPE_ERR: DOM Range Exception 2". At the

same time, single-selector queries like $('input[name=q]',sDiv) don't

crash. Also, the problem only happens if a context (sDiv) is an

element NOT YET ADDED to DOM.

Seems like quite a hypothetical situation? Nah, as I said I'm using

FlexiGrid and it took me a few hours to track down the reason why my

application no longer works under jQuery 1.3.2 :(

Attachments (0)
Change History (3)

Changed August 07, 2009 08:00PM UTC by erobitaille comment:1

We were able to solve this issue with a quick patch to jquery SortOrder function line #2118

before:

aRange.selectNode(A);

aRange.collapse(true);

bRange.selectNode(B);

bRange.collapse(true);

after:

aRange.setStart(a, 0);

aRange.setEnd(a, 0);

bRange.setStart(b, 0);

bRange.setEnd(b, 0);

Changed August 31, 2009 01:31PM UTC by zachleat comment:2

I can confirm that the proposed change from erobitaille fixed the issue for me in Safari.

Changed October 02, 2009 02:04AM UTC by dmethvin comment:3

resolution: → invalid
status: newclosed

Solved, not a jQuery core issue.