Reputation: 7
I want to remove a class from the whole page or just from the class "nav-link". I guess that's not working because it would make no sense to remove a class from a class,but yea
document.getElementsByClassName("nav-link").classList.remove("active");
Upvotes: 0
Views: 1098
Reputation: 2731
If you want to remove a particular class from all the elements, you gotta iterate through each element, and remove the class.
document.querySelectorAll('.nav-link').forEach(item => item.classList.remove('active'));
Upvotes: 2
Reputation: 666
Please try this... I have used window load function and My code is find Classname "active" and remove the class.
$(window).on("load", function(){
$(document).find(".active").removeClass("active");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="navLink active">abc</div>
<div class="navLink2 active">abc</div>
<div class="navLink3 active">abc</div>
<div class="navLink4 active">abc</div>
Upvotes: 0
Reputation: 741
Get elements by class list returns multiple elements, you should remove the class you want from each one of the resulting elements..
Upvotes: 0