JDev JDev - 2 years ago 91
jQuery Question

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

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


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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download