Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Mobile Losing Style After Updating DOM
    primarykey
    data
    text
    <p>A question similar to this has been posted several time, but I cannot find a solution that works. Hopefully, someone can help!</p> <p>I am using jQuery Mobile 1.1 and jQuery 1.7.2, so I'm on the most recent stable releases. I want to create a dynamic page header. Using this HTML code, it works fine:</p> <pre><code> &lt;div data-role="page" id="levela"&gt; &lt;div data-role="header" id="hdr_levela"&gt; &lt;h1&gt;Title&lt;/h1&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>So I then go to dynamically create the title. I change the HTML to this:</p> <pre><code> &lt;div data-role="page" id="levela"&gt; &lt;div data-role="header" id="hdr_levela"&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>And added the following jQuery code:</p> <pre><code> // Set the header var dirHeader = $('#hdr_levela'); dirHeader.append('&lt;h1&gt;' + title+ '&lt;/h1&gt;'); </code></pre> <p>The title appears, but is not styled. I have found several posts about this. In the jQuery Mobile Documentation, it says:</p> <p>"However, if you generate new markup client-side or load in content via Ajax and inject it into a page, you can trigger the create event to handle the auto-initialization for all the plugins contained within the new markup. This can be triggered on any element (even the page div itself), saving you the task of manually initializing each plugin (listview button, select, etc.).</p> <p>For example, if a block of HTML markup (say a login form) was loaded in through Ajax, trigger the create event to automatically transform all the widgets it contains (inputs and buttons in this case) into the enhanced versions. The code for this scenario would be:</p> <pre><code>$( ...new markup that contains widgets... ).appendTo( ".ui-page" ).trigger( "create" ); </code></pre> <p>So I tried several things. After the above code, I added the following:</p> <pre><code>dirHeader.trigger("create"); </code></pre> <p>This had no effect. So I tried to put it on the actual append itself:</p> <pre><code>dirHeader.append('&lt;h1&gt;' + folderName + '&lt;/h1&gt;').trigger("create"); </code></pre> <p>This had no effect. I then tried the process on the parent element (in this case, the id of the parent div is "levela"). So I tried this:</p> <pre><code>$('#levela').trigger("create"); </code></pre> <p>This also had no effect. At this point, I am completely lost. Every solution involves doing one of the things I have tried and is just not working. I must be missing something incredibly basic but I just can't seem to find it.</p> <p>Thanks in advance for your help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload