This should be really simple, but for some reason I just can't get it work. I have an array of class names that might exist on the page. I loop through this array and check if that class exists, if it does, I add that object to another array.
jQuery:
var class_list = ['class1', 'class2', 'class3'];
var classes = {};
$(function(){
if( class_exists() ){
console.log('Classes: '+JSON.stringify(classes));
}
});
function class_exists(){
var exists = false;
for( var i=0; i<class_list.length; i++ ){
//check if the class exists:
if( $('.'+class_list[i])[0] ){
classes[class_list[i]] = $('.'+class_list[i]);
exists = true;
}
}
return exists;
}
The output of this is Uncaught TypeError: Converting circular structure to JSON
. I expected to see something like {'class1': [object Object], 'class2': [object Object]}
. This should be so simple, where am I going wrong?