[jQuery] Trying to create a dynamic TOC nested list

[jQuery] Trying to create a dynamic TOC nested list


Hey fellow jQuery fans,
i am trying to pull all headings out of a page and create a unordered
list in the sidebar, which should then act as navigation help.
$(document).ready(function() {
    $('#sidebar #references').after("<ul class='subnav'>");
    $('.main h3.caps a').each(function(i, val) {
        $('ul.subnav').append(this.firstChild);
    });
});
I am able to append the pure text of the anchors, but i can't create
the list. I was looking at the wrap-function of jquery, but didn't
figure out how to use it in this scenario.
Can somebody explain me how to get the value of this.firstChild
sorrounded by "<li></li>"?
Thanks in advance,
Michael