I'm not sure how should I resolve the following event bubbling situation in jQuery.
I have a link inside a list element (li), which has an on click event. I would like to put an action on li element, which would call link event (click) and call action on li if user clicks a link inside the list element (I always want to trigger click event on li when li or anything inside is clicked).
How should I accomplish this?
Here's the HTML code:
<li>
<img src="images/img.png" />
<a href="/remote/path" data-remote="true">Link</a>
</li>
and jQuery code (which obviosly won't work):
$("li a").click(function(e) {
e.preventBubble = true;
});
$("li").click(function() {
$el = $(this).find('a');
$el.click();
$(this).addClass('active');
});
What is the most elegant solution to this?
Thanks for help!