Hy everyone i’ve been trying for 2 days to modify this script so i can call it whenever a link had the id=”paginations” unsuccessful of course ( just because i’m a newb ).
What exactly i am trying to do is call this function to load and change the #content even if the link is inside the #content. Like this.
<div class="pagination">
<a href="test.php">clik2</a>
</div>
I’ve trying to create a function and call it with onClick but i was unsuccessful. This script works perfectly if the link is outside the #Content but i need it to work inside the #Content also. Any ideas please ?
$(document).ready(function() {
var hash = window.location.hash.substr(1);
var href = $('.pagination a').each(function(){
var href = $(this).attr('href');
if(hash==href.substr(0,href.length-5)){
var toLoad = hash+'.html #content';
$('#content').load(toLoad)
}
});
$('.pagination a').click(function(){
var toLoad = $(this).attr('href')+' #content';
$('#content').hide('1000',loadContent);
$('#load').remove();
$('#wrapper').append('<span id="load"></span>');
$('#load').fadeIn('slow');
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
function loadContent() {
$('#content').load(toLoad,'',showNewContent())
}
function showNewContent() {
$('#content').delay(100).show('fast',hideLoader());
$(window).scrollTop('');
}
function hideLoader() {
$('#load').delay(300).fadeOut('fast');
}
return false;
});
});
If the link is being added with javascript, which I think is what you are trying to do then you need to use the live function. Currently you have
Which should be replaced with:
You can read more about live here. The problem with click is that it does not get added to elements that are created after the function has been set, where as live will.