On This Page
Query - CSS
The CSS Manipulation methods in Query allow you to easily modify classes and CSS properties of elements, providing powerful tools for dynamic styling in your Semantic UI components.
addClass
Adds one or more classes to the set of matched elements.
Syntax
Parameters
Name | Type | Description |
---|---|---|
className | string | One or more class names to be added |
Returns
Query object (for chaining).
Usage
Standard
Shadow DOM
removeClass
Removes one or more classes from the set of matched elements.
Syntax
Parameters
Name | Type | Description |
---|---|---|
className | string | One or more class names to be removed |
Returns
Query object (for chaining).
Usage
Standard
Shadow DOM
toggleClass
Toggles one or more classes for the set of matched elements.
Syntax
Parameters
Name | Type | Description |
---|---|---|
className | string | One or more class names to be toggled |
Returns
Query object (for chaining).
Usage
Standard
Shadow DOM
hasClass
Determines whether any of the matched elements are assigned the given class.
Syntax
Parameters
Name | Type | Description |
---|---|---|
className | string | The class name to search for |
Returns
boolean
- true
if the class exists on any of the matched elements, false
otherwise.
Usage
Standard
Shadow DOM
css
Get the value of a computed style property for the first element in the set of matched elements or set one or more CSS properties for every matched element.
Syntax
Parameters
Name | Type | Description |
---|---|---|
propertyName | string | CSS property name |
value | string | Value to set for the CSS property |
options | object | Additional options for getting/setting CSS |
Options
Name | Type | Default | Description |
---|---|---|---|
includeComputed | boolean | false | Include computed styles when getting CSS value |
Returns
- When getting: The value of the specified CSS property.
- When setting: Query object (for chaining).
Usage
Standard
Shadow DOM
computedStyle
Get the value of a computed style property for the first element in the set of matched elements.
CSS Performance - This is an alias for
css
with{ computedStyle: true }
option. In many cases you will want to get the css style as it appears in the page and not just if it has a css rule applied. This however can trigger a reflow, which means this behavior is opt-in.
Syntax
Parameters
Name | Type | Description |
---|---|---|
propertyName | string | CSS property name |
Returns
The computed value of the specified CSS property.
Usage
Standard
Shadow DOM
cssVar
Get or set the value of a CSS custom property (CSS variable).
Syntax
Get
Set
Parameters
Name | Type | Description |
---|---|---|
variableName | string | The name of the CSS variable (without ’—‘) |
value | string | (Optional) The value to set for the variable |
Returns
- When getting: The value of the specified CSS variable.
- When setting: Query object (for chaining).