user7430373
user7430373

Reputation:

How to get var value from another .js file with jQuery

In my first .js file I have a global var with name workitemInspectorValue.

How will I get the value of workitemInspectorValue with jQuery from the second .js file?

Upvotes: 0

Views: 250

Answers (1)

Hugo G
Hugo G

Reputation: 16484

This has nothing to do with jQuery. In JavaScript global variables are visible to all included files that are run after the definition. If you included the files in the correct order, you should be able to see and use the global var.

Aside from that, consider scoping your variables. For example, pass them as function parameters or if you really need, attach them to ONE global object or the DOM (e.g. as attribute to document). A common approach is also storing data at the objects in question on the DOM. Consider the data() technique, which is a standard and well supported by jQuery.

Upvotes: 2

Related Questions