For my menu i want to check if an clicked element has e certain classname. If it has, a specific action should follow, otherwise not. Herefore i have the following approach that doesn;t work..
$(function(){
$("a").click(function(event){
if(this.hasClass("noLink")){
event.preventDefault();
alert("no link here");
}
});
});
..
<a href="page.html" title="Title" class="topNav noLink" id="site">Link</a>
The code above won’t work, it will go to the page.html and i don’t get my alert. What am i doing wrong here?
I also tried if(this.hasClass("noLink") == 'true'){ but that neither did the trick..
Any help is appreciated!
Try this: