Answer the question
In order to leave comments, you need to log in
Why event.target doesn't match the clicked element?
https://codepen.io/pawel-beloborodow/pen/wvKrWjo?e...
In the condition if I click, I should get the element I click on. And I get it.
But if I compare it with myself, I get false why.
Answer the question
In order to leave comments, you need to log in
because it event.target
returns native HTMLElement
and $('.test') is a jquery wrapper that is not a DOM element.
It is checked like this:
$(document).on("click", event => {
let test = event.target;
console.log(
test instanceof HTMLElement, // true
$('.test') instanceof HTMLElement // false
)
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question