I have this variable var which has a classList with some classes. Let’s say there is a class in there called “ssp“. How can i get this class only having the var and knowing the name of the class.
I can imagine that it should ne something like var.classList.get("ssp")
and in my mind the get()
function should return the element but I don’t think there is such method. So does anyone know how to do this?
In my case this is my code:
function newOption(father) {
// here there should be this 'questionaire' div which has a classlist and one of those is called 'question'
var father = document.getElementById('questionaire').classList.item(); // here i am trying to access it
// here i am just adding another class to the father
const op = document.createElement('div');
op.classList.add("option");
op.innerHTML = '<div contenteditable="true">Option</div><input type="checkbox" class="box">';
father.appendChild(op);
}