Name/fragment link not working on dynamically built page

134 views Asked by At

I'm building a page dynamically:

document.body.appendChild.....

and trying to build/link to sections with fragment identifies on the fly.

when I attach an anchor element with a fragment link (after creating/attaching the corresponding div: yournamehere):

<a href="#yournamehere">yournamehere</a>

The link does not work (scroll to the div named yournamehere). Why? Do fragment URLs not work when a page is built via JavaScript?

edit: pseudo-js:

var div = makeElement("<div name='yournamehere'></div>");
    document.body.appendChild(div);

var a = makeElement('<a href="#yournamehere">yournamehere</a>')
    document.body.appendChild(a);
0

There are 0 answers