diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2019-11-18 22:10:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-18 22:10:55 +0100 |
commit | 05184cc448f4ed7715ddd6a5d724e167882415f1 (patch) | |
tree | c1b240fa57e4b0824ea04f9a1fd951722c1ce83c /src | |
parent | d0ce00cdfa680f1f0c38460bc51ea14079ae8b07 (diff) | |
download | jquery-05184cc448f4ed7715ddd6a5d724e167882415f1.tar.gz jquery-05184cc448f4ed7715ddd6a5d724e167882415f1.zip |
Selector: Make empty attribute selectors work in IE again
qSA in IE 11/Edge often (but not always) don't find elements with an empty
name attribute selector (`[name=""]`). Detect that & fall back to Sizzle
traversal.
Interestingly, IE 10 & older don't seem to have the issue.
Fixes gh-4435
Closes gh-4510
Diffstat (limited to 'src')
-rw-r--r-- | src/selector.js | 4 | ||||
-rw-r--r-- | src/selector/rbuggyQSA.js | 16 | ||||
-rw-r--r-- | src/selector/var/whitespace.js | 2 |
3 files changed, 18 insertions, 4 deletions
diff --git a/src/selector.js b/src/selector.js index 019f25d62..66abe7935 100644 --- a/src/selector.js +++ b/src/selector.js @@ -5,6 +5,7 @@ import documentElement from "./var/documentElement.js"; import indexOf from "./var/indexOf.js"; import pop from "./var/pop.js"; import push from "./var/push.js"; +import whitespace from "./selector/var/whitespace.js"; import rbuggyQSA from "./selector/rbuggyQSA.js"; import support from "./selector/support.js"; @@ -41,9 +42,6 @@ var i, // Regular expressions - // https://www.w3.org/TR/css3-selectors/#whitespace - whitespace = "[\\x20\\t\\r\\n\\f]", - // https://www.w3.org/TR/css-syntax-3/#ident-token-diagram identifier = "(?:\\\\[\\da-fA-F]{1,6}" + whitespace + "?|\\\\[^\\r\\n\\f]|[\\w-]|[^\0-\\x7f])+", diff --git a/src/selector/rbuggyQSA.js b/src/selector/rbuggyQSA.js index f638fc429..2c853a0f1 100644 --- a/src/selector/rbuggyQSA.js +++ b/src/selector/rbuggyQSA.js @@ -1,8 +1,10 @@ import document from "../var/document.js"; import isIE from "../var/isIE.js"; +import whitespace from "./var/whitespace.js"; var rbuggyQSA = [], - testEl = document.createElement( "div" ); + testEl = document.createElement( "div" ), + input = document.createElement( "input" ); testEl.innerHTML = "<a href=''></a>"; @@ -19,6 +21,18 @@ if ( isIE ) { rbuggyQSA.push( ":enabled", ":disabled" ); } +// Support: IE 11+, Edge 15 - 18+ +// IE 11/Edge don't find elements on a `[name='']` query in some cases. +// Adding a temporary attribute to the document before the selection works +// around the issue. +// Interestingly, IE 10 & older don't seem to have the issue. +input.setAttribute( "name", "" ); +testEl.appendChild( input ); +if ( !testEl.querySelectorAll( "[name='']" ).length ) { + rbuggyQSA.push( "\\[" + whitespace + "*name" + whitespace + "*=" + + whitespace + "*(?:''|\"\")" ); +} + rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join( "|" ) ); export default rbuggyQSA; diff --git a/src/selector/var/whitespace.js b/src/selector/var/whitespace.js new file mode 100644 index 000000000..dcac814c7 --- /dev/null +++ b/src/selector/var/whitespace.js @@ -0,0 +1,2 @@ +// https://www.w3.org/TR/css3-selectors/#whitespace +export default "[\\x20\\t\\r\\n\\f]"; |