reset attributes from element in javascript

To reset the attributes of an element in JavaScript, you can use the removeAttribute() method. This method removes the specified attribute from an HTML element. You can call this method on an element and pass in the attribute name as a parameter. Here's an example:

index.tsx
const myElement = document.querySelector('#my-element');

// Remove the "class" attribute
myElement.removeAttribute('class');

// Remove the "style" attribute
myElement.removeAttribute('style');

// Remove the "data-foo" attribute
myElement.removeAttribute('data-foo');
270 chars
11 lines

In the example above, we first select the element with the ID "my-element" using the querySelector() method. We then call removeAttribute() on the element for each attribute that we want to remove. This will reset the attributes of the element back to their default values.

gistlibby LogSnag