Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading with AJAX and going to anchor in loaded content
    primarykey
    data
    text
    <p>I'm building a website to organize comics collections.</p> <p>So you have on the left a list of yours comics and if you click on one of them, the page with the details about that comic is loaded on the right with AJAX with the jQuery <code>load()</code> function.</p> <p>I don't have a page for every comic but for every serie (one for all the "Walking dead", one for all the "Spiderman"....) so on every page that can be a lot of different comics.</p> <p>However when clicking on a specific comic I not only want to load the correct page but also to go at the correct position in this page.</p> <p>I have anchors in every page (#i12,#i13 with a unique number each time).</p> <p>How can I, after the content is loaded using AJAX, go to the correct anchor ? I tried to dynamically modify the page URL (adding a #i12 at the end) but without success.</p> <p>I was using <code>document.location.hash</code>, bad idea ?</p> <p><hr> A very simple example : when clicking on the link the page is loaded into the div and I would like the page to scroll to the anchor <code>#i120</code></p> <p>Main page : </p> <pre><code>&lt;div id="list"&gt; &lt;a href="test.php#i120"&gt;Go to num 120&lt;/a&gt; &lt;/div&gt; &lt;div id="content"&gt; &lt;/div&gt; </code></pre> <p>Javascript : </p> <pre><code>$("a").live('click',function (event) { $("#Content").load(this.href); event.stopImmediatePropagation(); event.preventDefault(); }); </code></pre> <p>Page Test.php : </p> <pre><code>&lt;div id="i1"&gt;Text1&lt;/div&gt; ... ... &lt;div id="i120"&gt;Text120&lt;/div&gt; </code></pre>
    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.
 

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