Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8577579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:11:30+00:00 2026-06-11T20:11:30+00:00

With CSS selectors a selector string body > h1.span subscribes to a specific type

  • 0

With CSS selectors a selector string body > h1.span subscribes to a specific type of nodes in the tree. Does anyone know how this is done?

Selectors for transformations, how does the browser select the result set? And is there a trick to making it efficient?

I imagine there being some sort of hierarchical type-tree for the entire structure to which the nodes subscribe and which is what is used when doing the selector queries — but this is only a guess.

Does anyone know the real answer? Or even more interesting, what would be the best way to do dynamic lookups on a tree based on jQuery/CSS search queries?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:11:31+00:00Added an answer on June 11, 2026 at 8:11 pm

    Most major browsers process a page and create a document hierarchy or document tree based on the elements in the page, according to the DOM. When applying CSS, they typically iterate the document tree, working on a per-element basis and performing right-to-left matching on the candidate selectors in a stylesheet for each element, then apply CSS rules based on these matches according to the CSSOM. This means for a selector like body > h1.span for example, a browser first checks each element to see if it’s an h1 with a class of span, then checks if it’s a direct descendant of body.

    Depending on the implementation, there may be some optimizations to filter more likely non-matching cases. For instance, checking the namespace, tag name, ID, or class name, before attempting any other matching routines, as those are the most common ways to distinguish elements.

    This per-element matching pattern allows a browser to effectively “subscribe” a selector to changes in the DOM, because all a browser would need to do (I imagine) is to look at changes in the DOM and apply rules and reflow the elements that were changed accordingly.

    That is over-simplifying it, though. It also mainly refers to selector matching in a stylesheet. It doesn’t describe every selector implementation, because the spec doesn’t define implementations.

    For example, browsers implement the Selectors API (document.querySelector() et al) differently, even though it uses CSS selectors for querying the DOM. In particular, there is no subscription model whatsoever; the node lists returned by Selectors API methods aren’t dynamically updated. From §6.2 Finding Elements:

    The NodeList object returned by the querySelectorAll() method MUST be static, not live ([DOM-LEVEL-3-CORE], section 1.1.1). Subsequent changes to the structure of the underlying document MUST NOT be reflected in the NodeList object. This means that the object will instead contain a list of matching Element nodes that were in the document at the time the list was created.

    jQuery seems to perform right-to-left matching of selectors as well, according to some answers on this site, but I haven’t found any supporting sources. It also has a number of optimizations such as body and ID selectors being read first, etc. And like the Selectors API, jQuery returns a static list of nodes that matched at the time its selector engine was invoked; it won’t subscribe to changes in the DOM and update the node list accordingly (if you need to subscribe to DOM changes and delegate event handlers, you need to use .on() or a similar method with a selector).

    It’s worth noting that one major optimization that jQuery employs is to defer to the Selectors API for matching selectors first. This means it uses the browser’s native implementation rather than JavaScript. If the selector is valid CSS and supported, document.querySelectorAll() returns a node list. If it errors out otherwise, jQuery falls back to its own selector engine, Sizzle, for querying the DOM.

    Again, it’s not strictly identical to browsers’ implementation of CSS selectors, in particular because jQuery selectors and CSS selectors are not the same thing, even though one is an adaptation of the other.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this codepen there is a css selector &:hover what does that selector match?
Motivation To utilize Selenium's CSS selector mechanism alongside with CSS attribute selectors and the
This CSS selector picks up elements without a class attribute: a:not([class]) This CSS selector
I need CSS selector that match all input tags where type is not checkbox
I want to parse this CSS Selector (and others of a similar form): div.class1#myid.class2[key=value]
This popular Stack Overflow question explained why CSS selectors are parsed right to left.
I have the following string which is a CSS selector: #downloads > ul >
I wonder what the the part ::-webkit-search-decoration do in the CSS selector for input[type=search]::-webkit-search-decoration
What is the simplest way to extract css selectors as strings? Given this as
Can anyone help me transform my xPath to CSS Selector? The code i want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.