The HTML as follows:
What I know:
- TAG name is random ;
id
is random, alsoclass
;- The common attribute is that they all have
classname
attr.
How should I remove them just use js
?
The HTML as follows:
What I know:
id
is random, also class
;classname
attr.How should I remove them just use js
?
You can use .removeAttribute
in the HTMLelement, here is an example:
function removeClassname() {
const elements = document.querySelectorAll('[classname]')
elements.forEach((element) => {
element.removeAttribute('classname')
})
}
[classname] {
background-color: red;
}
<div classname="abc">asdasd</div>
<button classname="abc">asdasd</button>
<p classname="abc">asdasd</p>
<button onclick="removeClassname()">Remove classname</button>