{"library":"query-selector","title":"Cross-Environment querySelectorAll Implementation","description":"This package provides a JavaScript implementation of `querySelectorAll`, designed to offer consistent DOM querying functionality across various environments, including Node.js (with `jsdom`) and older browser contexts. The current stable version is 2.0.0, released in August 2019. The project exhibits a slow release cadence, with no substantial updates since its last major version. Its key differentiator is providing a polyfill-like solution for `querySelectorAll` where native implementations might be absent or incomplete, ensuring broader compatibility for selector-based DOM manipulation. It serves as a foundational utility for projects requiring reliable CSS selector-based element retrieval outside of modern browser engines.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install query-selector"],"cli":null},"imports":["const querySelectorAll = require('query-selector').default;","import querySelectorAll from 'query-selector';","<!-- In HTML: --><script src=\"/build/query-selector-standalone-debug.js\"></script>\n<script>console.log(querySelectorAll('#t span'));</script>"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const querySelectorAll = require('query-selector').default;\nconst { JSDOM } = require('jsdom');\n\n// Create a JSDOM environment for Node.js to simulate a browser DOM\nconst dom = new JSDOM('<html><body><div id=\"t\"><span>1</span><span>2</span></div></body></html>');\nconst doc = dom.window.document;\n\nconsole.log('--- Using native doc.querySelectorAll ---');\nconst nativeElements = doc.querySelectorAll('#t span');\nconsole.log('Native result length:', nativeElements.length);\nconsole.log('Native first element innerHTML:', nativeElements[0].innerHTML);\n\nconsole.log('\\n--- Using query-selector package ---');\nconst customElements = querySelectorAll('#t span', doc);\nconsole.log('Custom result length:', customElements.length);\nconsole.log('Custom first element innerHTML:', customElements[0].innerHTML);\n\n// Demonstrates calling the custom querySelectorAll with a specific context (the document)\n// The output should be identical, showcasing its polyfill capability.\n// In a browser, the 'doc' argument would often be 'document' or 'this'.","lang":"javascript","description":"This quickstart demonstrates how to use `query-selector` within a Node.js environment by integrating it with `jsdom` to provide a document context. It shows both the native `querySelectorAll` (if available in the JSDOM instance) and the package's implementation, highlighting its usage and expected output.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}