question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

querySelector fails on class selector

See original GitHub issue

How to reproduce:

  1. 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>`);
    
  2. 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:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Sebmastercommented, Jul 3, 2016

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.

0reactions
aincommented, Jul 8, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found