2

How to invoke a jquery method which in another jquery method?
For example:
In a.js, I define a variable var url = "ssh";
In b.js, I want to use url in a.js, how can I use?

4 Answers 4

1

As known, a variable in the global scope should be accessible to all scripts loaded after it is declared. Include both JavaScript file in one HTML file, place b.js after a.js so that you can access url variable. Like this

<script type="text/javascript" src="a.js"></script>
<script type="text/javascript" src="b.js"></script>
Sign up to request clarification or add additional context in comments.

Comments

0

you can directly access that variable in file b.js. if you include both file in your html page. Because variable / method of any file is global.

Comments

0

if your var url is global and a.js is imported before b.js then you can use your variable url directly

example inside b.js alert(url)

Comments

0

See what are you looking for is absolutely accessible in terms of correct ordering and a global variable.

In file a.js you have a global var like this:

var url = "ssh";

Then you can use this var in b.js if a.js is placed before this file or you can say loaded before b.js.

So the order of script files would be:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.