Global javascript variable inside ready
Posted
by
w0rldart
on Stack Overflow
See other posts from Stack Overflow
or by w0rldart
Published on 2012-06-22T08:50:30Z
Indexed on
2012/06/22
9:16 UTC
Read the original article
Hit count: 244
JavaScript
|jQuery
Which is the right way of declaring a global javascript variable? The way I'm trying it, doesn't work
$(document).ready(function() {
var intro;
if ($('.intro_check').is(':checked')) {
intro = true;
$('.intro').wrap('<div class="disabled"></div>');
};
$('.intro_check').change(function(){
if(this.checked) {
intro = false;
$('.enabled').removeClass('enabled').addClass('disabled');
} else {
intro = true;
if($('.intro').exists()) {
$('.disabled').removeClass('disabled').addClass('enabled');
} else {
$('.intro').wrap('<div class="disabled"></div>');
}
}
});
});
console.log(intro);
© Stack Overflow or respective owner