querySelector fails on class selector
See original GitHub issueHow to reproduce:
-
Create
jsdom
:global.document = jsdom.jsdom(`<!doctype html> <html style="margin-top:10px;"> <head> <meta charset="utf-8"> </head> <body style="margin-top:20px;" class="ui-page"> </body> </html>`);
-
Retrieve
.ui-page
:let page = document.querySelector('.ui-page');
What happens:
page
is null.
What should happen:
page
should equal
let page = document.querySelector('body');
which is not null.
Version: 9.2.1
.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Why document.querySelector fails to find class name in ...
querySelector ('Lh') return a null. I have tried many permutations with a div as part of the search string but there must be...
Read more >What to do when querySelector() fail on valid selectors
What to do when querySelector() fail on valid selectors. Lots of special characters are valid for IDs, classes, and names.
Read more >Avoid Errors With document.querySelector ... - | Ryan Dejaegher
When querySelector doesn't find a matching selector, the value of the variable will be null . For example: var missingElement = document.
Read more >Element.querySelector() - Web APIs | MDN
The querySelector() method of the Element interface returns the first element that is a descendant of the element on which it is invoked ......
Read more >HTML DOM Document querySelector() Method - W3Schools
Both querySelector() and querySelectorAll() throw a SYNTAX_ERR exception if the selector(s) is invalid. Tutorials: The CSS Selectors Tutorial · The CSS ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Maybe the class has been removed by the time you try to retrieve the element? Try logging
jsdom.serializeDocument(document)
and see if it still contains the class.Confirmed, implementation error.
document.write
had killed the classes on body element.Sorry for the noise, hopefully it’ll prove useful for someone having an hiccup on the same topic.