0

I have A, B html and A, B javascript files.

And, How can I move global variable used in A JavaScript directly to B Javascript?

example A javascript)

var pos;
for (var i = 0; i < 10; i++) {
$(document).on('click', '#length_' + i, function() {
  pos = $(this).attr('id');
  });
}

pos (global variable) -> B javascript ?

I'm so sorry, I can't english well...

ko_ma
  • 651
  • 2
  • 7
  • 18

1 Answers1

1

If i understood your question correctly, you want to access var pos in your other JS file. To achieve this you need to load your A.js which contains global variable file first eg.

<script src="a.js" />
<script src="b.js" />

this way you can access global variable defined in a, in b.

amoeba
  • 512
  • 5
  • 22