I'm trying to include on my website the Quicksand script, but I failed badly.
Firebug gives me this error: 65 Uncaught TypeError: Cannot call method 'split' of undefined
:
for this script:
jQuery.noConflict();
jQuery(document).ready(function($){
// Clone applications to get a second collection
var $data = $("#portfolio-items").clone();
//NOTE: Only filter on the main portfolio page, not on the subcategory pages
$('#portfolio-terms ul li').click(function(e) {
$("ul li").removeClass("active");
// Use the last category class as the category to filter by. This means that multiple categories are not supported (yet)
var filterClass=$(this).attr('class').split(' ').slice(-1)[0];
jquery.custom.js:65 Uncaught TypeError: Cannot call method 'split' of undefined (repeated 6 times)
if (filterClass == '.all current') {
var $filteredData = $data.find('#portfolio-');
} else {
var $filteredData = $data.find('#portfolio-[data-type=' + filterClass + ']');
}
$("#portfolio-items").quicksand($filteredData, {
duration: 800,
easing: 'swing',
});
$(this).addClass("active");
return false;
});
});
See here: http://stakk.it/
what is the error?
thank you and sorry for my bad english!
If .attr("class")
returns undefined
, you can't call .split
on it because .split
is a method of the String
object and can't be called on undefined
. You need to store the result of .attr("class")
and then only split it if it is not undefined
.
var filterClass = $(this).attr('class');
filterClass = filterClass ? filterClass.split(' ').slice(-1)[0] : '';
now filterClass will contain what you expect, or an empty string.
Edit: you could replace $(this).attr('class')
with this.className
, pulled from removed answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With