Note that there are some explanatory texts on larger screens.

plurals
  1. POjavascript & jQuery mobile: navigate to <div data-role="page"></div>
    primarykey
    data
    text
    <p>I am relatively new to jQuery Mobile. So, I do not know every corner of the framework capabilities. </p> <p>I am currently facing some problems with history and dynamic page navigation.</p> <p>Basically, I want to achieve the following:</p> <p>I have a web page that changes content by button clicks. The "home" page should display the <code>&lt;div data-role="page" id="list_root"&gt;...&lt;/div&gt;</code>. By clicking a button the page should navigate to <code>&lt;div data-role="page" id="list_123"&gt;...&lt;/div&gt;</code>. I want to be able to get back to the content of div "#list_root" by using the back button.</p> <p>Prior to using jQuery I did implement this by myself with <code>history.pushState(divContent, null, "#list_&lt;id&gt;")</code> and replacing the old content with the new one. However, the pushState plugin is deactivated by default using jQuery mobile.</p> <p>The button that is pressed to navigate is defined like the following:</p> <pre><code>&lt;a href='#list_&lt;id&gt;' class='...'&gt;...&lt;/a&gt; </code></pre> <p>I did try to implement the creation of the new div content (for list_) by implementing a callback for "onhashchange". But this event gets never called.</p> <p>Futhermore, if I would be able to create the content when the link was clicked, I would like to show the content of <code>&lt;div id="list_&lt;id&gt;"&gt;</code>, replacing the previous content. </p> <p>Since the application presents mass data - I did not want to use jQuery mobiles' nested list.</p> <p>Do you have any hints for me how I can implement this using the framework functionality?</p> <p><strong>EDIT:</strong></p> <p>I have the following situation:</p> <pre><code>&lt;div data-role="page" class="type-interior" id="main_window"&gt; &lt;div id="current" class="ui-content" data-role="content" role="main"&gt; &lt;div id="list_root" data-url="list_root"&gt; &lt;div id="list_123" data-url="list_123" data-role="page"&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>As you see "list_root" is the default "start page" and gets displayed as intended.</p> <p>I added an event listener for click() to dynamically create the content of <code>&lt;div id="list_123"&gt;</code> via:</p> <pre><code>document.addEventListener('click', function(e) { ... create it ... e.stopPropagation(); }, true) </code></pre> <p>This works.</p> <p>The button is created like the following: </p> <pre><code>&lt;a href="#list_123" data-role="button"&gt;List_123&lt;/a&gt; </code></pre> <p>The div content gets created successfully and after that the hash in the url changes to #list_123. But the page is not displayed. Is the problem here, that <code>&lt;div data-role="page" id="list_123"&gt;...&lt;/div&gt;</code> stands within the <code>&lt;div data-role="page" class="type-interior" id="main_window"&gt;</code> tag? I'll try that next!</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