ClassName of of closest() element returning undefined

170 Views Asked by At

I am trying to retrieve the class names (and hence use it) of an element that i am retrieving using the target.closest() method. However when i try to apply classNames or even do something using classList method the result comes undefined.

I looked at a similar question on stackoverflow but the person was using an html collection and by using a single element, his issue was resolved. However my issue remains the same.

    const cuisineList = document.querySelector('.cuisinesList');

    cuisineList.addEventListener('mouseover', function (e) {
    const hovered = e.target.closest('li');
    console.log("hello", hovered.classNames);
})

Sidenote: the "hovered" element in the given code are correctly received. There is no issue in that. The result of the hovered element is the very list element that I want to manipulate.

0

There are 0 best solutions below