Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document.querySelector misbehaving on 'tagName#id' #576

Closed
Tanimodori opened this issue Sep 2, 2022 · 3 comments
Closed

document.querySelector misbehaving on 'tagName#id' #576

Tanimodori opened this issue Sep 2, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@Tanimodori
Copy link
Contributor

It ignores the #id part and search for the tagName only.

const window = new Window();
const document = window.document;
const content = document.createElement('div');
content.innerHTML = `<div id="foo">bar</div>`;
document.body.appendChild(content);

console.log(document.querySelector('div#foo').outerHTML);
// <div><div id="foo">bar</div></div>

console.log(document.querySelector('#foo').outerHTML);
// <div id="foo">bar</div>

On my Chrome, both console.log print <div id="foo">bar</div>.

Environment

  • happy-dom 6.0.4
  • Chrome 105.0.5195.102
@Tanimodori
Copy link
Contributor Author

Tanimodori commented Sep 2, 2022

Of course you can search #foo in this example, but some libraries may rely on this feature (e.g. document.querySelector should return null when tagName does not match)

@Tanimodori
Copy link
Contributor Author

Tanimodori commented Sep 3, 2022

According to this W3C selector document, E#myid is a valid selector and considered as "an E element with ID equal to myid."

Tanimodori added a commit to Tanimodori/happy-dom that referenced this issue Sep 3, 2022
capricorn86 added a commit that referenced this issue Oct 6, 2022
#576@patch: Fix querySelector issue on tag and id.
@capricorn86
Copy link
Owner

Thank you for reporting and contributing @Tanimodori! 🙂

Your PR has now been merged and released.

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v7.0.5

@capricorn86 capricorn86 added the bug Something isn't working label Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants