Reputation: 145
I have two delegate functions working..but I want that if the img is clicked avoid the click on the <li>.
<li><img src='img.png'/></li>
$('#listview').delegate('li img', 'click', function(){
alert('img clicked!');
});
$('#listview').delegate('li', 'click', function() {
window.open("details.php?id" + $(this).attr('id'), '_blank');
});
If the image (inside the li) is clicked I would like NOT to open that page details. Currently, when I click the image it alerts plus show the new page..how can I avoid that?
Upvotes: 0
Views: 51
Reputation: 38102
Try using event.stopImmediatePropagation():
$('#listview').delegate('li img', 'click', function(e){
e.stopImmediatePropagation();
alert('img clicked!');
});
to prevent event buble up the DOM tree.
Upvotes: 3