0

I want to remove a div by class with JavaScript from an existing website.

<div id="application-form">
   <div class="show-pl">Test</div
</div>
LauraV6
  • 1
  • 5
  • Write to the console: `document.querySelector('#application-form .show-pl').className = '';`. – Teemu Jun 20 '19 at 07:42
  • 1
    Possible duplicate of [How to add and remove classes in Javascript without jQuery](https://stackoverflow.com/questions/26736587/how-to-add-and-remove-classes-in-javascript-without-jquery) – Germa Vinsmoke Jun 20 '19 at 07:44
  • 1
    Please clarify if you want to remove "div by class" or "class from a div"? Question title differs from the question text. – Yury Tarabanko Jun 20 '19 at 07:47

2 Answers2

2

use removeAttribute('class')

document.querySelector('.show-pl').removeAttribute('class');
<div id="application-form">
  <div class="show-pl">Test</div>
</div>

If you want to remove element with required class, use document.querySelector('.show-pl').remove();

document.querySelector('.show-pl').remove();
<div id="application-form">
  <div class="show-pl">Test</div>
</div>
random
  • 7,756
  • 3
  • 19
  • 25
  • @LauraV6 - Or if you need to support obsolete browsers like IE: The old way was to call [`removeChild`](https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild) on the parent: `var element = document.querySelector('.show-pl'); element.parentNode.removeChild(element);` – T.J. Crowder Jun 20 '19 at 12:59
0

If you want to remove class, just use listClass.remove('classname') like this:

document.querySelector('your-selector').classList.remove('classname-to-remove')

Nickce
  • 9
  • 1