Languages
[Edit]
EN

JavaScript - remove data attribute from HTML element

4 points
Created by:
Niac
508

In this short article, we would like to show how to remove data-* attribute from any element using JavaScript.

Quick solution:

or:

 

Practical examples

Edit

1. Using removeAttribute() method

Edit

data-* attributes are can be removed in the same way as normal attributes.

2. Using dataset property

Edit

DOM provides dataset property that gives access to data-* attributes collection. data-* attributes names are converted to pascalCase notation and available in JavaScript API. The attribute remove operation can be performed with delete keyword.

 

See also

Edit
  1. JavaScript - add data attribute 

Alternative titles

  1. JavaScript - delete data attribute
  2. JavaScript - remove element data attribute
  3. JavaScript - delete element data attribute
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join