diff --git a/CHANGELOG b/CHANGELOG index 11c52ca..c4a3071 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Fix issue where a Selector query rooted on a node that had not been attached to the document failed in IE. [#464 state:resolved] (jddalton, kangax, Douglas Fraser, Andrew Dupont) + * Fix Selector to match elements with attributes containing hyphens. [#285 state:resolved] (leiyou, jddalton, kangax) * Make sure Form.reset always returns a reference to the receiver element. [#309 state:resolved] (Phil, kangax) diff --git a/src/dom/selector.js b/src/dom/selector.js index 158877c..3dc4791 100644 --- a/src/dom/selector.js +++ b/src/dom/selector.js @@ -485,8 +485,23 @@ Object.extend(Selector, { id: function(nodes, root, id, combinator) { var targetNode = $(id), h = Selector.handlers; - if (!targetNode) return []; - if (!nodes && root == document) return [targetNode]; + + if (root == document) { + // We don't have to deal with orphan nodes. Easy. + if (!targetNode) return []; + if (!nodes) return [targetNode]; + } else { + // In IE, we can check sourceIndex to see if root is attached + // to the document. If not (or if sourceIndex is not present), + // we do it the hard way. + if (!root.sourceIndex || root.sourceIndex < 1) { + var nodes = root.getElementsByTagName('*'); + for (var j = 0, node; node = nodes[j]; j++) { + if (node.id === id) return [node]; + } + } + } + if (nodes) { if (combinator) { if (combinator == 'child') { diff --git a/test/unit/selector_test.js b/test/unit/selector_test.js index c756fbe..4fb7bf2 100644 --- a/test/unit/selector_test.js +++ b/test/unit/selector_test.js @@ -371,6 +371,21 @@ new Test.Unit.Runner({ 'div.is_counted' ); }, + + testSelectorNotInsertedNodes: function() { + window.debug = true; + var wrapper = new Element("div"); + wrapper.update("