This will add a disabled class to all A tags where their href matches the id of any element which has the selected class:
$(function() {
$("a").removeClass('disabled');
$('.selected').each(function() {
$('a[href=#' + $(this).attr('id') + ']').addClass('disabled');
});
// If by 'disabled', you mean you want the link not to work, then add this:
$('a.disabled').on('click',function(e) {
alert('you can\'t do that');
e.preventDefault();
return false;
});
});
Example here: http://jsfiddle.net/dtxan/4/