I am facing an issue where I need to add a class to a group of <a> tags. I tried using the querySelectorAll method to select all the a tags, but for some reason, the class is not being added to them.
Here is the code snippet that I have tried:
var qc=document.querySelectorAll(".Label ul li a");
qc.className+="newcls";
You can see the result in this JSFiddle link.
Although I managed to achieve it using jQuery, I want to avoid using jQuery and find a solution using plain JavaScript.
document.addEventListener("DOMContentLoaded", function() {
var elements = document.querySelectorAll(".Label ul li a");
elements.forEach(function(element) {
element.classList.add("newcls");
});
});