Jump to content

JQuery - document ready - ajax - link clicks not working


Perad

Recommended Posts

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;
	}
});
});

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.