Skip to content

[cssom] Implement CSSStyleRule.p.matches #3670

@jridgewell

Description

@jridgewell

With style rules nested inside @media and @support conditions, it's a bit difficult to determine if a style rule applies to an element. Is it possible to expose a matches method that would do this for us?

const div = document.querySelector('div');
const span = document.querySelector('span');

{
  // Eg, `@media screen { div { color: red; } }`
  const rule = document.styleSheets[0].cssRules[0].cssRules[0];

  rule.matches(div);
  // => true
  rule.matches(span);
  // => false
}

{
  // Eg, `@media not screen { div { color: red; } }`
  const rule = document.styleSheets[1].cssRules[0].cssRules[0];

  rule.matches(div);
  // => false
  rule.matches(span);
  // => false
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions