मुख्य सामग्री पर जाएँ
Skillpedia
वेबसाइट और UI (frontend)75k · #2865

has-selector

यह क्या करती है

यह स्किल ऐसा कोड खोजती है जो JavaScript से पैरेंट की स्टाइल बदलता है, उसके children की सामग्री के आधार पर। यह सरल, CSS-आधारित स्टाइलिंग चाहने वाले डेवलपर्स के लिए है।

कब इस्तेमाल करें

  • ✓जब आपकी स्क्रिप्ट कंटेनर में इनपुट बदलने पर उसमें class जोड़ती है।
  • ✓जब आप सिर्फ़ सामग्री के आधार पर पैरेंट को स्टाइल करने के लिए JavaScript लिखते हैं।
  • ✓जब आप ऐसी स्टाइलिंग कोड कम करना चाहते हैं जिसे सिंक में रखना मुश्किल हो।

Skill का लिंक

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/has-selector/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/has-selector/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“क्या मैं जब child बदले तब पैरेंट को स्टाइल करने के लिए JavaScript की जगह CSS इस्तेमाल कर सकता हूँ?”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

एजेंट पैरेंट classes बदलने वाला JavaScript खोजता है और :has selector सुझाता है जो child शर्त पूरी होने पर पैरेंट को लक्षित करे। वह यह भी समझाता है कि :has, :is और :not से कैसे अलग है।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

Use :has() to style parent elements based on their descendants

Before :has(), styling a parent based on its children required JavaScript: detecting state, toggling classes, and keeping DOM and styles in sync. This created coupling between styling logic and application logic. :has() moves that relationship back into CSS where it belongs, reducing JavaScript complexity, eliminating class-toggling boilerplate, and making styling intent readable in the stylesheet itself.

Quick Reference

  • :has() selects an element when a matching descendant exists inside it
  • It is the parent selector CSS has needed for decades
  • Baseline support since late 2023 — all major browsers include it
  • Avoid complex :has() selectors in hot reflow paths — they can affect layout performance

Check

Look for patterns in this code where JavaScript toggles a class on a parent element based on the state or content of a child element. These are candidates for replacement with :has().

Fix

Replace the JavaScript class-toggling logic with a CSS :has() selector. Show the selector that targets the parent element when the relevant child condition is met.

Explain

Explain how the :has() pseudo-class works, how it differs from :is() and :not(), what descendant vs child combinators mean inside :has(), and how browser support stands today.

Code Review

Review the stylesheets and component JavaScript in this file. Flag any locations where a parent element's style is controlled by toggling a class from JavaScript based on child state — and show the equivalent :has() rule.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/css/has-selector

अक्सर पूछे जाने वाले सवाल

:has क्या करता है?

यह एक एलिमेंट को तब चुनता है जब उसके भीतर कोई मेल खाने वाला child या descendant मौजूद हो, जो पहले CSS में संभव नहीं था।

क्या यह व्यापक रूप से समर्थित है?

स्किल कहती है कि 2023 के अंत से सभी प्रमुख ब्राउज़रों में :has का baseline समर्थन है।

क्या यह पेज को धीमा कर सकता है?

स्किल बार-बार पुनर्गणना होने वाले layout क्षेत्रों में जटिल :has selectors से चेतावनी देती है।

जानकारी

लेखक का मूल विवरण

Use when reviewing stylesheets or components that use JavaScript to toggle classes on parent elements based on child state, form input values, or content presence — :has() may replace the JavaScript entirely.

repo: thedaviddias/Front-End-Checklist

लोकप्रियता

GitHub स्टार
75k
रैंकिंग में स्थान
#2865
लाइसेंस
MIT
अपडेट की गई
31/10/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills