I have this function inside of a javascript class:
this.checkSections = function(){
jQuery('#droppable #section').each( function() {
nextId = jQuery(this).next().attr('id');
if (nextId != 'small' && nextId != 'large'){
jQuery(this).remove();
this.sections --;
this.followArticles = 0;
}else{
articles = 0;
obj = jQuery(this).next();
while (nextId == 'small' || nextId == 'large'){
articles++;
obj = obj.next()
nextId = obj.attr('id');
//alert(nextId);
}
this.followArticles = articles;
alert(this.sections);
}
});
}
the alert(this.sections); (last lines) gives output of undefined although the sections is defined and used.
what could be the problem?
thisdoes not relate to what you think it does. jQuery has overwritten it for use in$(this). I'm sure there is another method that's simpler, but I always use underscore.js's_.bind()function to pass through the parent'sthisdata.thiswould be the element being iterated, and you're using$(this).remove()on the line above, so what makes you thinkthiswould reference a class on the next line ?