CSS Styles API

css.has()

Validates whether the passed inline CSS styles are applied to the matched DOM elements.

  • Accepts arguments as strings and arrays of strings.
    You can pass inline CSS styles as individual arguments, as an array, or as a string separated by commas or spaces, using "kebab-case", "camelCase", or "snake_case" formats.
    Each value is seen as a new argument.
  • Returns true if all matched DOM elements contain all passed CSS styles, otherwise, returns false.
Example:
// <div>0</div>
// <div style="margin: 10px">1</div>
// <div style="background-color: red; margin: 10px">2</div>
// <div style="background-color: red; margin: 10px">3</div>

$('div').css.has('margin');
// false

$('div ? 1').css.has('margin');
// true

$('div ? 1, 2').css.has('margin-left');
// true

$('div ? 1, 2').css.has('background-color');
// false

$('div ? 2, 3').css.has('backgroundColor', 'margin_left');
// true

$('div ? 2').css.has('background_color, margin');
// true

$('div ? 2').css.has('background-color marginLeft');
// true

$('div ? 2').css.has(['backgroundColor', 'margin-bottom']);
// true

$('div ? 2').css.has('margin', 'border');
// false