const input= document.querySelector('.search');
input.addEventListener('keyup', e=>{
console.log(this.value);
});
This doesn't do what I expected, since I'm calling the event listener on the input. I figured 'this' would be the input, but instead it's referring to the window. I'm confused about why this is. If anyone can explain it that'd be great.
To solve this I created a function and passed it into the listener.
function value(){
console.log(this.value)
}
input.addEventListener('keyup', value)
I'm still confused about why doing it this way allows 'this' to refer to the input.