Bug Tracker

Opened 11 years ago

Closed 10 years ago

#4554 closed bug (invalid)

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 :(

Change History (3)

comment:1 Changed 10 years ago by erobitaille

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);

comment:2 Changed 10 years ago by zachleat

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

comment:3 Changed 10 years ago by dmethvin

Resolution: invalid
Status: newclosed

Solved, not a jQuery core issue.

Note: See TracTickets for help on using tickets.