Advertisement

Google Ad Slot: content-top

JS Change Attribute Dom

~1 min read · JS
On this page

Attributes in HTML elements can be added, updated, or removed dynamically using JavaScript. The setAttribute, getAttribute, hasAttribute, and removeAttribute methods, as well as property access, are commonly used to manipulate attributes.


setAttribute:

Adds or updates an attribute on an element.

Example
Existing text
Try it yourself

getAttribute:

Retrieves the value of an attribute.

Example
Existing text
Try it yourself

removeAttribute:

Removes an attribute from an element.

Example
Existing text
Try it yourself

hasAttribute:

Checks if an element has a specific attribute.

Example
Existing text
Try it yourself

style:

Add styles in js

Example

style in js

Existing text
Try it yourself