relatively new jQuery user(used it in the pass but really trying to understand it now).
Am trying to create my own jQuery pagination with ajax, so far my code looks like so:
$(document).ready(function(){
$('.pigs ul.pigspagination li a').live('click', function(e) {
e.preventDefault();
var url = $(this).attr('href');
if(url.match('^http')){
return true;
} else {
var element = $(this).closest(".pigs");
$(element).append('<div id="loading"><img alt="Loading..." src="loading.gif" /></div>');
$('#loading').fadeIn('normal');
$(element).load(url + ' ' + element);
return false;
}
});
});
The code basically says on click of ".pigs ul.pigspagination li a" load the parent element which is ".pigs" from the the given url then load the same fragment from the url. However this does not seem to be working:
$(element).load(url + ' ' + element);
I assume that am loading the url then am adding a space then saying for the element which is referenced from var element = $(this).closest(".pigs");
if your wondering why i just cant put $(element).load(url + ' .pigs');
It is because i reference .pigs multiple times and its automatic since it the php gallery script i wrote.
The html looks roughly like this:
<div class="pigs">
<ul class="pigs-gallery">
<li><a href="the link" target="_blank"></a></li>
...
</ul>
<ul class="pigspagination">
<li><a href="pagination link">< Prev</a></li>
...
<li><a href="pagination link">Next ></a></li>
</ul>
</div>
times however many more galleries are loaded.
Any ideas?
--------------EDIT for bfavaretto-------------- Tried this
var frag = $(this).closest(".pigs").attr('id');
$(element).load(url + ' #' + frag);
it loads just that suction but removes all the code, my guess is frag is being passed badly. the .attr('id'); will get the id by its self, not the '#' right?
Finale code if anyone is interested:
$(document).ready(function(){
$('.pigs ul.pigspagination li a').live('click', function(e) {
e.preventDefault();
var url = $(this).attr('href');
if(url.match('^http')){
return true;
} else {
var element = $(this).closest(".pigs");
$(element).append('<div id="loading"><img alt="Loading..." src="loading.gif" /></div>');
$('#loading').fadeIn('normal');
var frag = $(this).closest(".pigs").attr('id');
$(element).load(url + ' #' + frag);
return false;
}
});
});