How about something like this (demo)?
$(function(){
// find the nav & headers
var nav = $('#chapters li a'),
articles = $('#main article > h1');
// now assign an id/href to each
nav.each(function(i){
nav.eq(i).attr('href', '#article-' + i);
articles[i].id = 'article-' + i;
});
});