# classList.remove should work if no class is assigned.

**URL:** <https://es.discourse.group/t/classlist-remove-should-work-if-no-class-is-assigned/2333>\
**Category:** 💡 Ideas\
**Created:** [March 26, 2025, 11:46am UTC](https://es.discourse.group/t/classlist-remove-should-work-if-no-class-is-assigned/2333 "2025-03-26T11:46:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaroslav.tavgen](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jaroslav.tavgen/32/2732_2.png) [@jaroslav.tavgen](https://es.discourse.group/u/jaroslav.tavgen)\
**Post date:** [March 26, 2025, 11:46am UTC](https://es.discourse.group/t/classlist-remove-should-work-if-no-class-is-assigned/2333/1 "2025-03-26T11:46:25Z")

</div>

let domElement = document.getElementById(`domElement`);  
domElement.classList.remove(`I don't exist`);

The browser will throw an error: "Cannot read properties of undefined (reading 'remove')".

But it does not make any sense. If I need to remove some class name then why should I check if it exists? I want to remove it anyway.

---

<div class="post-metadata">

**Author:** ![bakkot](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bakkot/32/22_2.png) [@bakkot](https://es.discourse.group/u/bakkot)\
**Post date:** [March 26, 2025, 5:17pm UTC](https://es.discourse.group/t/classlist-remove-should-work-if-no-class-is-assigned/2333/2 "2025-03-26T17:17:55Z")

</div>

a.) This forum is for JavaScript, and the thing you're asking about is in the [DOM spec](https://github.com/whatwg/dom), which is a different thing.

b.) The error you're getting indicates that the `classList` property doesn't exist at all, possibly because you're on an old browser or have a typo or something. Removing a class which isn't present does in fact work fine.
