I have a dropdown menu where the menu items are filled dynamically from the DB using laravel blade template language. I'm trying to fire on click events on the menu items by JQuery click() by a class selector function but nothing is happening.
Here's the menu:
<ul class="dropdown-menu">
@foreach ($categories as $cat)
<li data-menu="">
<a class="dropdown-item category_item" href="#" data-toggle="dropdown" data-categoryId="{{ $cat->id }}">
<i class="feather icon-package"></i>{{ $cat->name }}</a>
</li>
@endforeach
</ul>
</li>
</ul>
</div>
An here's the JS in the base template where the menu is being included using @include()
<script>
$(function() {
$(".category_item").click(function(e) {
e.preventDefault();
var $cat_id = $(this).data('categoryid');
console.log("logging: I was cliked", $cat_id);
});
});
</script>
Could someone catch what I'm doing wrong?