Reputation: 35
I'm trying to filtering two links (containing 'next' and 'previous'), then if it finds one of them I append a link to load a photo. My problem is that I want append only one link at time, the Load Next link if it find the Next text and the Prev. link if it find the Previous text. If I write this it won't work
$(document).ready(function(){
if ($(".forumrow table").find('a').filter(':contains(Next)')) {
$('.blockhead a').filter('a:last[href^="http://site.com/showgallery.php?cat="]').html('<a class="loadnextone" href="#">Load next</a>');
$('a.loadnextone').live("click",function(event) {
event.preventDefault();
var next1 = $(".forumrow table").find('a').filter(':contains(Next)').attr('href');
var next1cat1split = $('.blockhead a').filter('a:last[href^="http://site.com/showgallery.php?cat="]').attr('href').split(/=/)[1];
$(".nextoz").load(next1+" ol.floatcontainer");
});
}
if ($(".forumrow table").find('a').filter(':contains(Prev)')) {
$('.blockhead a').filter('a:last[href^="http://site.com/showgallery.php?cat="]').html('<a class="loadprevone" href="#">Load prev</a>');
$('a.loadprevone').live("click",function(event) {
event.preventDefault();
var prev1 = $(".forumrow table").find('a').filter(':contains(prev)').attr('href');
var prev1cat1split = $('.blockhead a').filter('a:last[href^="http://site.com/showgallery.php?cat="]').attr('href').split(/=/)[1];
$(".prevozz").load(prev1+" ol.floatcontainer");
});
}
});
How can I do?
Upvotes: 0
Views: 61
Reputation: 69905
You should check for length
property like this. jQuery
always returns a jQuery
object even if the selector do not return anything.
if ($(".forumrow table").find('a').filter(':contains(Next)').length > 0){
}
and
if ($(".forumrow table").find('a').filter(':contains(Prev)').length > 0) {
}
Upvotes: 3