I can't seem to find an example of what I'm trying to do here but I'm sure it's possible.
Consider the following:
<div id=main_nav>
<a href=/url/>LINK</a>
<a href=/url/>LINK</a>
<a href=/url/>LINK</a>
<a href=/url/>LINK</a>
</div>
How can I run a function when a link
within #main_nav
is clicked before then following the link
?
The below doesn't work as the link is followed before the function is run.
$('#main_nav a').click(function() {
// Some Function
});
EDIT
I'm actually trying to clear a cookie with the JQuery cookie plugin when the links are clicked. I'm not sure if this is relevant or not.
The Clear cookie code is:
$.cookie('TMMenu', null);
TMMenu is the correct name and the plugin is loaded.
EDIT
Sorry everyone. The problem was actually with the JQuery Cookie plugin documentation.
$.cookie('TMMenu', null);
as described in the readme doesn't seem to work. This does:
$.cookie('TMMenu', null, { path: '/', expires: -5 });