- From: Austin Keener <notifications@github.com>
- Date: Thu, 04 Mar 2021 07:15:24 -0800
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Thursday, 4 March 2021 15:15:36 UTC
The confusion here is that the expectation is that `Element.querySelector` would only match selectors based on the context of the `baseElement` (in this case, `#inner-table`) such that it feels correct to believe that `document.querySelector('#inner-table tbody tr')` and `document.querySelector('#inner-table').querySelector('tbody tr')` are the same, as if the latter were the same as the form via simply prepending `#inner-table` onto the selector. However, this is not the case. Given the [docs on how Element.querySelector works](https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector#return_value), the entire document is matched against the query, and then it filters all matched queries to find those that are children within the `baseElement`, which is `#inner-table` in this case. Thus, the first element that satisfies `tbody tr` and is _also_ a child of `#inner-table` would be `#outer-table > tbody > tr > td > #inner-table > thead > tr` due to all of `#inner-table` being inside of a `tbody` -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/dom/issues/956#issuecomment-790690973
Received on Thursday, 4 March 2021 15:15:36 UTC