Is there a way to access a variable outside of the function that it's declared in?
var checkWidth = function () {
var $width = $(window).width();
}
$(window).on('resize', checkWidth);
// access $width here with the value from the resize
Solution:
var $width = $(window).width();
$(window).resize(function () {
var $resizeWidth = $(window).width();
updateWidth($resizeWidth);
});
function updateWidth(a) {
width = a;
// use the new width here
}