I've an anchor within an list-item. Both elements have an event. I'd like to avoid clicking the list-item when clicking the anchor within.
I'd like to avoid chaos. I found this functions but I wasn't able to use them as I wanted:
That's the code:
// HTML
<ul>
<li id="1">Item #1 <a href="" class="delete">[DEL]</a></li>
<li id="2">Item #2 <a href="" class="delete">[DEL]</a></li>
<li id="3">Item #3 <a href="" class="delete">[DEL]</a></li>
<li id="4">Item #4 <a href="" class="delete">[DEL]</a></li>
</ul>
// JS
$("ul").sortable();
$(document).on("click", "li", function() {
alert("list-item clicked.");
});
$(document).on("click", "a.delete", function(e) {
e.preventDefault();
if (confirm("Del?")) {
alert("list-item clicked.");
}
// do nothing
});
Here's a fiddle: http://jsfiddle.net/UtE87/1/
What's the best way?