ctrl + k
On This Page
attr
removeAttr
prop
Query - Attributes
Attribute methods in Query allow you to get, set, and remove attributes on DOM elements.
attr
Gets or sets attributes on elements.
Syntax
Get
Set
Parameters
Name | Type | Description |
---|---|---|
attributeName | string | The name of the attribute to get |
Returns
Get
Query object (for chaining).
Set
- Single Element - The attribute value of that element.
- Multiple Elements - An array of attribute value , one for each matched element.
Usage
Get an Attribute
Set an Attribute
Set Multiple Attributes
removeAttr
Removes an attribute from each element in the set of matched elements.
Boolean Attributes - This is helpful for boolean attributes where setting a value like
checked="false"
will actually result in checked being set.
Syntax
Parameters
Name | Type | Description |
---|---|---|
attributeName | string | The name of the attribute to remove |
Returns
Query object (for chaining).
Example
prop
Gets or sets properties on an element.
Component Properties - There are special helpers
setting
andsettings
to set component properties for web components.
Syntax
Get
Set
Parameters
Parameters
Name | Type | Description |
---|---|---|
propertyName | string | The name of the property to set |
value | any | The value to set for the property |
Returns
Get
- Single Element - The property value of that element.
- Multiple Elements - An array of property value , one for each matched element.
Set
Query object (for chaining).