Tim Marshall Tim Marshall - 1 year ago 82
Javascript Question

$(e.target) is <i></i> and not the containing <div>...</div>

I have been working on a large script which checks the data-action and now I've implemented a hover to show some icons; like so:

<div class="Flag" data-action="mail-flag"><i class="fa fa-flag" aria-hidden="true"></i></div>

However with this not having plain text within and instead an icon,
if ($(e.target).attr('data-action')) {
does not work as
is the

How can I get
if ($(e.target).attr('data-action')) {
to work on the
without adding the
to the

Answer Source

You can check the element, then its parent. First, check if


exists. If it does not, use