views:

510

answers:

3

I'm doing a jQuery multiple selector find:

element.find("fieldset, input[type=hidden], input[type=text], :radio")

and in Chrome version 1 it gives this error "INVALID_NODE_TYPE_ERR: DOM Range Exception 2" on line 722 of jquery's selector.js

aRange.selectNode(a);

in context:

function(a, b) {
    var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange();
    aRange.selectNode(a);
    aRange.collapse(true);
    bRange.selectNode(b);
    bRange.collapse(true);
    var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange);
    if (ret === 0) {
     hasDuplicate = true;
    }
    return ret;
}

in this case, a is a HTML hidden input field. From what I can find, it seems to be an issue with the older webkit version, as this error doesn't occur in the new beta of Chrome (probably because it never hits this code because it implements document.documentElement.compareDocumentPosition see selector.js#703).

To step around this problem, I've replaced the multi-selector with four single selects which I merge together which works fine, but it's really ugly:

elements = element.find('fieldset')
.add(element.find('input[type=hidden]'));
.add(element.find('input[type=text]'));
.add(element.find(':radio'));

Is this really the only way around this, or is there something else I can do?

UPDATE There is a thread about this on the Sizzle discussion forum, a possible patch to the Sizzle (jQuery selector) code has been posted, this may find its way into jquery core. It seems to only be an issue when doing a multiple selector on dynamic code

+1  A: 

if the problem is the web browser, then sadly there is nothing you can do but wait for an update, or use the multiple selectors and merge the result sets. From what it looks like, this wouldn't be a big performance hit at all, and thus I wouldn't worry about it.

Scott M.
This was my thought, I was just hoping there was a less ugly way of doing it
Glenn Slaven
A: 

Have you tried...

element.find(['fieldset', 'input[type=hidden]', 'input[type=text]', ':radio'])

?

Matt
Unfortunately that returns nothing :(
Glenn Slaven
A: 

For reference the entirety of the DOM and rendering is just Apple's WebKit so any bugs you see should be reported to http://bugs.webkit.org -- Chrome doesn't have its own unique engine.

olliej