<button class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button" aria-expanded="true">
<span class="visible-sm-inline visible-md-inline visible-lg-inline">Sort by</span>
<span class="visible-xs-inline"><i class="fa fa-fw fa-sort"></i></span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu pull-right">
<li><a href="#" class="newest_to_oldest" data-sort="newest_to_oldest"><i class="fa fa-fw"></i> Newest to Oldest</a></li>
<li><a href="#" class="oldest_to_newest" data-sort="oldest_to_newest"><i class="fa fa-fw"></i> Oldest to Newest</a></li>
<li><a href="#" class="most_posts" data-sort="most_posts"><i class="fa fa-fw"></i> Most posts</a></li>
<li><a href="#" class="zero" data-sort="zero"><i class="fa fa-fw"></i> Post senza risposta</a></li>
<li><a href="#" class="most_views" data-sort="most_views"><i class="fa fa-fw fa-check"></i> Most Views</a></li></ul>
I am encountering an issue where I need to detect a click event on a specific element within the above code snippet:
<li><a href="#" class="most_views" data-sort="most_views"><i class="fa fa-fw fa-check"></i> Most Views</a></li></ul>
The problem arises because upon clicking this element, the page reloads, preventing me from executing my desired operation. Ideally, I would like to perform my operation upon clicking the element and then have the page reload. However, I am unsure if this is achievable. The jQuery code I have tried using is as follows:
$('a[data-sort]').click(function() {
console.log("CLICK DAT SORT");
if ($(this).is('[data-sort="most_views"]')) {
// do my operation
}
});
If anyone has a solution or can offer assistance with this issue, it would be greatly appreciated.