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

:scope (I guess) breaks normal querySelector #42

Closed
AlexWayfer opened this issue Jan 24, 2018 · 5 comments
Closed

:scope (I guess) breaks normal querySelector #42

AlexWayfer opened this issue Jan 24, 2018 · 5 comments

Comments

@AlexWayfer
Copy link
Contributor

Microsoft Edge.

<div class="parent">
  <p class="child">
  </p>
</div>

Without DOM4:

document.querySelector('.parent').querySelector('.child') // OK
document.querySelector('.parent').querySelector('.parent > .child') // OK
document.querySelector('.parent').querySelector('> .child') // Syntax Error
document.querySelector('.parent').querySelector(':scope > .child') // Syntax Error

With DOM4:

document.querySelector('.parent').querySelector('.child') // OK
document.querySelector('.parent').querySelector('.parent > .child') // null
document.querySelector('.parent').querySelector('> .child') // OK
document.querySelector('.parent').querySelector(':scope > .child') // OK
@WebReflection
Copy link
Owner

<div class="parent">
  <div class="parent">
    <p class="child"></p>
  </div>
</div>

now, without testing, what would you expect here?

document.querySelector('.parent').querySelector('.parent > .parent > .child')

it's like trusting a quirk to make things happen ... not sure this is a want fix, I'll think about it

@AlexWayfer
Copy link
Contributor Author

now, without testing, what would you expect here?

Ofc, .child.

Some references:

MDN web docs:

The first descendant element of baseElement which matches the specified group of selectors. The entire hierarchy of elements is considered when matching, including those outside the set of elements including baseElement and its descendants; in other words, selectors is first applied to the whole document, not the baseElement, to generate an initial list of potential elements. The resulting elements are then examined to see if they are descendants of baseElement. The first match of those remaining elements is returned by the querySelector() method.

Article:

It turns out that element.querySelectorAll doesn't match elements starting from element. Instead, it matches elements matching the query that are also descendants of element. Therefore, we're seeing three div elements: div.lonely, div.outer, div.inner. We're seeing them because they both match the div div selector and are all descendants of #my-id.

@WebReflection
Copy link
Owner

Ofc, .child.

that's because I've tweaked myself with the wrong test ... OK, fair ... I'll see if there's a fix for this without reinventing the whole querySelector engine.

PR welcome, if you have ideas.

@AlexWayfer
Copy link
Contributor Author

PR welcome, if you have ideas.

Sorry, I don't have for now :(

@AlexWayfer
Copy link
Contributor Author

I can try, but I don't see any info about contributing, testing, creating a PR…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants