diff --git a/CHANGELOG b/CHANGELOG index fd7e73c..d9690d1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Ensure selectors of the form "[href]" (attribute token with no preceding tag name) work properly. Closes #8870. [chao, kangax, Andrew Dupont] + * Performance optimizations for Element#descendantOf. Costliness should no longer be dependent on the difference in depth between the parent and the child. [Andrew Dupont] * Apply the workaround for the Firefox "blinking element" opacity=1 bug only to Firefox 1.5. [Thomas Fuchs] diff --git a/src/selector.js b/src/selector.js index 56d7745..6b4c8d9 100644 --- a/src/selector.js +++ b/src/selector.js @@ -436,6 +436,7 @@ Object.extend(Selector, { }, attrPresence: function(nodes, root, attr) { + if (!nodes) nodes = root.getElementsByTagName("*"); var results = []; for (var i = 0, node; node = nodes[i]; i++) if (Element.hasAttribute(node, attr)) results.push(node); diff --git a/test/unit/selector.html b/test/unit/selector.html index b42b4f5..3ad7664 100644 --- a/test/unit/selector.html +++ b/test/unit/selector.html @@ -173,6 +173,15 @@ assertEnumEqual($('link_1', 'link_2'), $$('a[class~=internal]')); }}, + testSelectorWithAttributeAndNoTagName: function() {with(this) { + assertEnumEqual($(document.body).select('a[href]'), $(document.body).select('[href]')); + assertEnumEqual($$('a[class~="internal"]'), $$('[class~=internal]')); + assertEnumEqual($$('*[id]'), $$('[id]')); + assertEnumEqual($('checked_radio', 'unchecked_radio'), $$('[type=radio]')); + assertEnumEqual($$('*[type=checkbox]'), $$('[type=checkbox]')); + assertEnumEqual($('with_title', 'commaParent'), $$('[title]')); + }}, + testSelectorWithUniversalAndHyphenTokenizedAttributeValue: function() {with(this) { assertEnumEqual([$('item_3')], $$('*[xml:lang|="es"]')); assertEnumEqual([$('item_3')], $$('*[xml:lang|="ES"]'));