There is the following code:

$('#PROGRAMS .options > div').click(function(){ var pid = this.value; $('#group .options > div').each(function(index, elem){ console.log(pid); }); }); 

From the function in each() pid variable is not visible. How to send it there?

  • one
    Because its value is undefined , does the div have any value ? This code works fine right on this page $ ('. Question-body'). Click (function () {var pid = 123; $ ('. Question-body'). Each (function () {console.log ( pid);});}); - etki
  • one
    As a last resort, you can always use the closure $ ('. Question-body'). Click (function () {var pid = 123; var func = (function (vpid) {return function (index, elem) {console.log (vpid );}}) (pid); $ ('. question-body'). each (func);}); But, as far as I understand, the inverse modification of a variable from a function is obtained only for objects. - etki
  • Probably morning tupnyak)) It is necessary var pid = this.getAttribute('value') - co11ter
  • More like, you don't understand the difference between a property and an attribute. - RubaXa

0