This question has already been answered:

How can I transfer a value from one function to another? So far I have this:

$( "#sss" ).click(function() { var itog = '111'; }); $( "#ddd" ).click(function() { alert(itog); }); 

I do not understand why it does not work.

Reported as a duplicate by members of Visman , Aries , tutankhamun , Rolandius , Alexander Petrov 27 Sep '15 at 18:26 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

2 answers 2

So? :)

 var itog; $( "#sss" ).click(function() { itog = '111'; }); $( "#ddd" ).click(function() { alert(itog); }); 
  • It helped! Thank you - Maksim Morozov

If var not specified, then the global variable window.itog :

 $( "#sss" ).click(function() { itog = '111'; }); $( "#ddd" ).click(function() { alert(itog); }); 
  • Thanks helped - Maksim Morozov
  • You don’t have to do it this way, at least - you can create an error for yourself, maximum - in strict mode it will stop working. If you really want to declare something in a global object, then so: window.foo = 5; - Aleksander K.