Perad Posted June 22, 2010 Share Posted June 22, 2010 I think this is a simple problem but I cannot work it out. When an ajax page is loaded into the #ajax div the links are now longer triggered. I think this is because the document is loaded and the function is run. When the new information comes into the page it isn't in the same scope as the click function. Is this correct? Is there a work around? function pageload(hash) { if(hash) { $.ajax({ url: "index.php?p="+hash+"&logo=0", cache: false, success: function(html){ $("#ajax").html(html); } }); } } $(document).ready(function(){ $.historyInit(pageload, "index.php"); // set onlick event for buttons $("a").click(function(){alert('click'); if (strpos($(this).attr('href'), 'index.php') !== false) { var hash = idToPath($(this).attr('href')); $.historyLoad(hash); return false; } }); }); Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted June 22, 2010 Share Posted June 22, 2010 It's because the events on the elements are placed when the dom is ready. The events wont be placed on the elements you load with the ajax call. There is a workaround though, take a look at live() Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.