I am trying to use variable in different function, I want to set global variable. Is there way how to do it?
I want something like this:
$('.bar1').animate({'height':'10' + "%"},1500, function() {
var bar1_height = $(".bar1").height() * 0.5;
});
and then use variable bar1_height elsewhere.
Declare
bar_heightoutside of your function.This will allow you to access it globally (i.e. both inside and outside of your function).
From MDN: