first page hidden in DOM causes duplicate page id on self submission

first page hidden in DOM causes duplicate page id on self submission

Hello,

I have a form page which is submitting to itself. By the way, the website is not ajax based, but still I would like to keep JQM ajax enabled.

So, on this form page there is an HTML element (#address-email) that I generate with a custom javascript :

$(document).on('pageshow', '#page-contact', function(){
    $('#address-email').html('<a href="mailto:xxxxxx">xxxxxxx</a>');
    $('#address-email').trigger('create');
});

Everything works fine, except that when I submit the form and get back to itself because some fields have errors, the HTML element is not generated anymore.
I found that it probably depends on JQM keeping the first ever initial page hidden within the DOM. If this first page happens to be the same form page (#page-contact), then when the form submits to itself there will be two pages within the DOM with THE SAME ID (#page-contact). This will cause my custom script to generate the HTML element markup only for the first page it finds in the DOM, since it has the same IS; but it is not the one that is going to be showed next by JQM.

Searching on the web I found a way to make JQM not store the first inistial page in the DOM, by using the _bindPageRemove function.
https://github.com/jquery/jquery-mobile/issues/2258

Is it a safe way, or should I better go with something else?

Could you please give me some hints or suggestions?


I'm using JQM 1.2.0.

Thank you.