I use jQuery's event object to get the target's parent. The code is:
event.target.parentElement
In Chrome it works, but in Firefox, it doesn't. I use alert()
to print the output.
event.target
is an URL in both Chrome and Firefox; but event.target.parentElement
in Chrome is [Element object], and in Firefox it is null
.
What should I do to solve this problem? I still wonder if IE will have this problem?
Thanks.
The event. target property returns which DOM element triggered the event. It is often useful to compare event. target to this in order to determine if the event is being handled due to event bubbling.
target is the element that triggered the event (e.g., the user clicked on) currenttarget is the element that the event listener is attached to.
To access the parent, you could do:
var par = $(event.target).parent();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With