weird behavior navigating to dynamically created page

weird behavior navigating to dynamically created page

I have a jquery mobile app where I add dynamic pages.
These pages get added to the dom and use the pagecontainer to navigate to the first page created. What happens is it navigates to the page that was created but immediately navigates back to the previous page, which also happens to be the first page in the dom.
What's going on????
  1. $.mobile.pageContainer.pagecontainer("change", "#" + firstpage);
  2. function changePage() { var activePage = $.mobile.pageContainer.pagecontainer("getActivePage"), nextPage = activePage.next("[data-role=page]"); if (nextPage.length != 0) { $.mobile.pageContainer.pagecontainer("change", nextPage); }; }