-4

in the following element to remove class='nav':

<p class="nav">I am Div1</p>
var p = document.getElementsByClassName("nav")[0];

i know that i can remove it using

p.classList.remove("nav")

But can i use Use :

p.className = "". 

Thank you in advance

Shinichi
  • 13
  • 1
  • 8

5 Answers5

1

with JQuery:

$('.nav').removeClass('nav');
nAviD
  • 2,784
  • 1
  • 33
  • 54
1

You can easily do it using element.classList.remove() in JavaScript

document.getElementsByClassName("nav")[0].classList.remove("nav");
keidakida
  • 713
  • 4
  • 12
1

try this one

p.classList.remove("env");
Shamama
  • 46
  • 5
1

You can remove it like this:

p.classList.remove('class1')
1

p.className=''; works perfectly as long as you want to remove all classes.
Otherwise use classList.remove

document.getElementById('btn').addEventListener('click', function() {
    var p = document.getElementsByClassName("nav")[0];
    p.classList.remove('nav');
});
.nav { background: red }
<p class="nav">I am Div1</p>
<button id ='btn'>Remove
Sascha
  • 4,576
  • 3
  • 13
  • 34