I search for a way to detect if a JQuery click target has a parent with a defined id $('#contextMenu')
in his DOM tree.
$("html").click(function(e) {
if ($(e.target).parents('#contextMenu')) {
alert('yes');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="contextMenu">
<li><a href="#"><i class="fa fa-user-plus"></i> share</a>
</li>
</ul>
How to do that?