I've got the following HTML structure.
<ul class="nav">
<li class="header">Sites</li>
<li><a href="#" class="showSite" >Site A</a></li>
<li><a href="#" class="showSite" >Site B</a></li>
</ul>
and I'm using this jQuery
$("body").on('click', '.nav', function( ) {
console.log ( 'nav clicked' )
// other code //
})
When the element with class nav
is clicked the jQuery runs, but I don't want it to run if one of the href links is clicked.
I've added console.log ( this )
to jQuery and it always shows the nav
element is clicked even when the href is clicked.
Just to add to this I do have some other jQuery that is triggered when .showSite
is clicked and that is running fine. I just don't want the .nav jQuery to run when the href is clicked.
Is it possible to not have the jQuery run when I click on the href's ?
Thanks
Update I think I may have solved this.
$("body").on('click', '.nav', function(e) {
console.log ( 'nav clicked' )
if ( $(e.target).attr('class') == 'showSite' ) return false
// other code //
})