One problem with toggle () is that it automatically calls event.preventDefault() . Here is one way that will allow you to leave the default action in place or only allow it to be called conditionally.
$("a").click(function(event){ var toggle = ($(this).data('toggle') == undefined) ? true : $(this).data('toggle'); console.log(toggle); if(toggle){ event.preventDefault(); } $(this).data('toggle', !toggle); });
source share