I need to get the value of a variable that's set in an each loop in jQuery. Here's what I have so far:
$('#conservatory_size .eva_toggle').each(function(){
if($(this).hasClass('active')){
var conservatory_size_total = $(this).data('price');
}
});
alert(conservatory_size_total);
The value is there and it works, because if I call the alert inside the each loop it shows the correct price. But out of the loop the variable doesn't even alert.
Any ideas?
UPDATE
If I do what you have said, the IF statement is blatantly working, declaring the variable before the loop.. is not.
$('#conservatory_size .eva_toggle').each(function(){
if($(this).hasClass('active')){
var conservatory_size_total = $(this).data('price');
alert('Has class.');
}
});
alert(conservatory_size_total);
