I tried to use this jQuery selector:
$(\"a:has(href*=#)\").click(function() { alert(\'works\'); });
but it doesn\'t seem to work. I
*= will filter attributes that contain the given string anywhere
*=
$("a[href*='#']").click(function() { alert('works'); });
Also note that
$("a[href^='#']").click(function() { alert('works'); });
will select any anchor whose href starts with a #
#