I'm trying to access this.type in my function activeTag(). When I click on it I want to add a custom class to the Tag.
I can't find if it's possible or if I'm just doing it wrong.
export default class Tag {
name;
searchType;
type;
constructor(name, searchType, genre) {
this.name = name;
this.searchType = searchType;
this.type= type;
}
tagDisplay() {
const tag = document.createElement('li')
tag.innerText = this.name;
this.searchType.appendChild(tag);
tag.addEventListener('click', this.activeTag)
}
activeTag() {
console.log(this); //return the element I clicked on
this.classList.add(this.type+'--selected'); //return undefined--selected
}
}