The jQuery :has selector matches elements that contain at least one descendant element meeting a given selector. It is a relational selector used to filter a set of DOM elements by their contents, so it is more expensive than simple class or tag matching and can affect page performance.
What the :has selector does in jQuery
The jQuery :has selector is a relational filter: it returns elements that contain matching descendants, rather than matching only the element itself. That makes it useful for content-aware selection, but it also means jQuery must inspect descendant structure, which is inherently more work than a simple class or tag lookup.
Why it is more expensive than simple selectors
Simple selectors such as classes, IDs and tags can often be resolved quickly by the browser’s selector engine. By contrast, :has asks a deeper question about the DOM tree, so the query may require broader traversal and more repeated checking, especially on large documents or when used in frequent update paths.
That extra cost is why :has is best treated as a precision tool, not a default choice. Used sparingly, it can reduce manual DOM bookkeeping; used casually, it can become a hidden performance tax in pages that already do a lot of rendering or event-driven DOM updates.
Where it fits in DOM scripting
:has is most useful when the state you care about lives in the child content, not in the parent’s own attributes. Common examples include selecting containers that include a validation message, a nested image, a checked control, or another descendant that changes how the parent should behave or look.
Because it is a relational selector, it can simplify code that would otherwise loop through nodes and test descendants manually. The trade-off is that readability and convenience should be weighed against selector cost, particularly in code that runs often, such as scroll handlers, live search, or repeated UI refreshes.
Performance and maintainability trade-offs
The main engineering trade-off is between expressive selectors and predictable cost. A selector that looks elegant in code review may still be expensive at runtime if it forces repeated descendant checks across a large subtree. In performance-sensitive front-end code, that cost can matter more than the brevity you gain.
NIST SP 800-53 Rev 5 Security and Privacy Controls is relevant here because secure configuration and system integrity practices both depend on controlling avoidable performance and complexity risks in software behaviour. For broader defensive guidance on unsafe resource use and inefficient patterns in web applications, OWASP API Security Top 10 and NIST Cybersecurity Framework 2.0 both reinforce the value of measurable, efficient, and well-governed controls.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
NIST CSF 2.0, NIST SP 800-53 Rev 5 and OWASP ASVS set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| NIST CSF 2.0 | PR.PS-05 — Configuration Management | Selector-heavy code needs disciplined configuration and predictable runtime behaviour. |
| Recommendation — Review high-cost DOM selector patterns and set performance baselines for front-end code. | ||
| NIST SP 800-53 Rev 5 | CM-7 — Least Functionality | Using only the selector power needed limits unnecessary complexity and runtime cost. |
| Recommendation — Prefer the simplest selector that meets the UI requirement and avoid unnecessary DOM traversal. | ||
| OWASP ASVS | V15 — Secure Coding and Architecture | Expressive selectors must still be used in maintainable, efficient application code. |
| Recommendation — Validate that selector logic is efficient and does not introduce avoidable application performance issues. | ||
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 3, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org