Reputation: 135
Need a bit of help with a Js error I am getting please:
Uncaught TypeError: $portfolio.isotope is not a function
//ISOTOPE FUNCTION - FILTER PORTFOLIO FUNCTION $portfolio = $('.portfolio-items'); $portfolio.isotope({ itemSelector : 'li', layoutMode : 'fitRows' }); $portfolio_selectors = $('.portfolio-filter >li>a'); $portfolio_selectors.on('click', function(){ $portfolio_selectors.removeClass('active'); $(this).addClass('active'); var selector = $(this).attr('data-filter'); $portfolio.isotope({ filter: selector }); return false; });
Upvotes: 1
Views: 14427
Reputation: 36652
If you don't want your script to run on pages that don't contain the required elements (.portfolio-items
), you can run your script conditionally based on the length
property of your element collection stored in $portfolio
:
$portfolio = $('.portfolio-items');
if ($portfolio.length) { // if 'length' is non zero. Enter block...
$portfolio.isotope({
itemSelector : 'li',
layoutMode : 'fitRows'
});
$portfolio_selectors = $('.portfolio-filter >li>a');
$portfolio_selectors.on('click', function(){
$portfolio_selectors.removeClass('active');
$(this).addClass('active');
var selector = $(this).attr('data-filter');
$portfolio.isotope({ filter: selector });
return false;
});
}
Upvotes: 4