Being fairly new to jQuery and the AJAX basics, I've been trying to set up some fairly simple dynamic loading.
I include a .js file setting up the click
event handler, and it looks like this:
var baseurl = document.getElementById("baseurl").getAttribute("href");
var pattern = new RegExp("[^/]+");
var page = "cnt/" + pattern.exec(window.location.href.substr(baseurl.length)) + ".php";
$(document).ready(function(){
$('a.ajax').bind('click',function(event){
event.preventDefault();
$('#content').load("cnt/" + pattern.exec(this.href.substr(baseurl.length)) + ".php")
})
});
Note that I do some changes to the file so the relative href "testing/" would turn into an absolute path to the file "cnt/testing.php".
My anchor tags look like this:
<a href="testing/" class="ajax">Link to testing page</a>
My problem is, that whenever new content is loaded into div#content the handler in my .js file is not registered for any links that may have appeared using AJAX. In other words the links will simply act as ordinary anchor-tags. I want it to load the next page using AJAX, just like it does with the first page.