Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery ajax call on click, only works once
    primarykey
    data
    text
    <p>I have this simple jquery code. On click it gets the URL of the tag, loads that page next to the current content, slides it and removes the old content. The state of the page is EXACTLY the same as before, same elements no extra classes or styles. The problem is that the next ajax call just doesn't work. Maybe I need to .unbind() something?</p> <p>I'm new to jquery and javascript so i'm quite lost. Thanks a lot for your help :) </p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function(){ loadPage(); }); function loadPage(url) { if (url == undefined) { $('body').load('index.html header:first,#content,footer', hijackLinks); } else { $.get(url , function(data) { $('body').append(data); $('body&gt;meta').remove(); $('body&gt;link').remove(); $('body&gt;title').remove(); $('body').append(direction); sm = $(window).width(); if(direction == "leftnav"){ $('body&gt;header:last,body&gt;#content:last,footer:last').css("left", "-" + sm + "px"); footerheight = $('body&gt;#content:last').outerHeight(false) + $('body&gt;header:last').outerHeight(true) ; $('footer:last').css("top", footerheight); $('body&gt;header,body&gt;#content,footer').css("-webkit-transition-duration","0.5s") $('body&gt;header,body&gt;#content,footer').css("-webkit-transform","translate(" + sm + "px,0px)"); }; if(direction != "leftnav"){ $('body&gt;header:last,body&gt;#content:last,footer:last').css("left", sm + "px"); footerheight = $('body&gt;#content:last').outerHeight(false) + $('body&gt;header:last').outerHeight(true) ; $('footer:last').css("top", footerheight); $('body&gt;header,body&gt;#content,footer').css("-webkit-transition-duration","0.5s") $('body&gt;header,body&gt;#content,footer').css("-webkit-transform","translate(-" + sm + "px,0px)"); }; setTimeout(function(){ $('body&gt;header:not(:last),body&gt;footer:not(:last),body&gt;#content:not(:last)').remove() },500); setTimeout(function() { $('body&gt;header,body&gt;footer,body&gt;#content').removeAttr('style') },500); }); } } function hijackLinks() { $('a').click(function(e){ e.preventDefault(); loadPage(e.target.href); direction = $(this).attr('class'); }); } &lt;/script&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.
    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