First, you code is equal to the following
$(function() {
$('a').each(function() {
var href = $(this).attr('href');
if(true) { $(this).attr('href', '/' + href); }
});
});
if you really want to update href based on condition, if statetment should be different:
$(function() {
$('a').each(function() {
var href = $(this).attr('href');
if(href.indexOf('http://') == -1 ) { $(this).attr('href', '/' + href); }
});
});
Another way would be the one offered by @Yogu, where you simple don't loop for links which you are not going to update