$('a').click(function (e) { if (! $(this).attr('href') ) { $(this).attr("href", "#"); e.preventDefault(); } });