Prepare repository for merge

This commit is contained in:
Angelos Chalaris
2023-05-01 22:35:56 +03:00
parent fc4e61e6fa
commit b3ad01863a
578 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,25 @@
---
title: Remove attributes
type: snippet
tags: [browser]
cover: new-york
author: chalarangelo
dateModified: 2022-07-20T05:00:00-04:00
---
Removes all attributes from an HTML element.
- Use `Element.attributes` and `Object.values()` to get all the attributes of the element.
- Use `Array.prototype.forEach()` and object destructuring to get the name of each attribute and `Element.removeAttribute()` to remove it from the element.
```js
const removeAttributes = element =>
Object.values(element.attributes).forEach(({ name }) =>
element.removeAttribute(name)
);
```
```js
removeAttributes(document.querySelector('p.special'));
// The paragraph will not have the 'special' class anymore
```