ctrl+k
Enter a search term above to see results...
Get, set, and remove HTML attributes and data attributes on elements.
$('selector').attr(name);$('selector').attr(name, value);$('selector').attr({ name: value, ... });Gets or sets attributes on elements.
| Name | Type | Description |
|---|---|---|
| name | string | The attribute name |
| value | string | The value to set |
$('selector').removeAttr(name);Removes an attribute from matched elements.
Boolean Attributes Use this for boolean attributes where
checked="false"would still be truthy.
| Name | Type | Description |
|---|---|---|
| name | string | The attribute name to remove |
Query object (for chaining).
$('selector').addAttr(name);$('selector').addAttr([name1, name2, ...]);Adds boolean attributes with empty string values. Equivalent to attr(name, '').
| Name | Type | Description |
|---|---|---|
| name | string | string[] | Attribute name or array of names |
Query object (for chaining).
$('selector').data();$('selector').data(key);$('selector').data(key, value);Gets or sets data-* attributes. Keys use camelCase and are converted to kebab-case in the DOM.
| Name | Type | Description |
|---|---|---|
| key | string | The data key (without data- prefix) |
| value | string | The value to set |
$('selector').removeData(keys);Removes data attributes from elements.
| Name | Type | Description |
|---|---|---|
| keys | string | string[] | Space-separated string or array of keys to remove |
Query object (for chaining).