I currently have a li
element containing a link. Inside of that link, I have an icon contained in an i
enclosure. When the user clicks that icon, a JavaScript .click()
is called, but the function of the parent element is called. I want the click on the icon to trigger the function meant to act on the icon solely.
If this helps, here's what my list item looks like:
<li class="saved-search">
<a href="#" class="" style="display:none">
<i style="display:none" class="fa fa-times-circle pull-right saved-search-delete"></i>
</a>
</li>
The Javascript looks like:
// this is the click event attached to the parent element of the icon
$('#save-search-name').keypress(function(event) {
...
});
// this is the icon click event
$('body').on('click', '.saved-search-delete', function(e) {
var saved_search_id = $(this).attr('data-search-id');
var searchJSON = {'id': saved_search_id };
// console.log('TROLOLOLOLOLOOOOOOL 2');
$.ajax({
url: '/adv/saved_search/',
contentType: 'application/json; charset=UTF-8',
type: "DELETE",
quietMillis: 200,
data: JSON.stringify(searchJSON),
success: function (response) {
Messenger().post({
type: 'success',
message: 'Saved search successfully deleted.',
showCloseButton: true,
hideAfter: 3,
});
}
}); // end ajax call
});
How do I isolate the act of clicking the icon with the desired behavior in my JavaScript? I still want the link to be clickable and to act as its default behavior should allow it. However, when the icon on top of it is clicked, I want only that icon's behavior to be triggered.