Utilisateur:Lgd/Test quater

$('span.foo a').each(function(){
  var url = $(this).parent().parent().prevAll(':header:first').find('span.editsection a').attr('href');
  if(url) {
    $(this).attr('href', url);
  }
});

Lorem

Section 1 bar

Section 2 bar

Section 3 bar

Section 4 bar

Section 5 bar