Consider the following very simple code excerpt:
(...)
<div id="myDiv"></div>
<script>
function appendSomeJQueryMobileStuff() {
$('#myDiv').append($('<select/>'));
}
appendSomeJQueryMobileStuff();
$(document).on('pageinit', function() {
appendSomeJQueryMobileStuff();
});
</script>
(try it out @ https://jsfiddle.net/ca544oob/)
Why is only the first <select> displayed with jQuery, but the second one isn't formatted at all? The only difference between the two function calls that I see is the moment when it happens.
And how do I fix this?
Using jQuery Mobile , select menu plugin is auto initialized on any page that contains a select menu, without any need for a
data-roleattribute in the markup.You can check detail from official documentation here. In your case, you are appendingselectonpageinit, So you need to initialize theselect menu pluginmanually by addingafter
Your final working code will be like..
Hope it will work for you .