1

I want to create a external java script file that should contain some validation functions. I want to add j query into my java script file, how can i do this,

I tried the following code but it seems to be not working,

var script = document.createElement('script');
script.src = 'http://code.jquery.com/jquery-1.11.0.min.js';
script.type = 'text/javascript';
document.getElementsByClassName('email')[0].appendChild(script);
4
  • Does this help?: stackoverflow.com/questions/7496789/… Commented Nov 4, 2015 at 12:39
  • instead of adding it to component, add it to head. var head = document.getElementsByTagName('head')[0]; head.appendChild(script); Commented Nov 4, 2015 at 12:40
  • Read about RequireJS. It's file/module loader. This solution clearly resolves dependencies. It's not easy at beginning, but very helpful. Commented Nov 4, 2015 at 12:47
  • what's wrong with a <script> tag Commented Nov 4, 2015 at 12:49

1 Answer 1

-2

Ideally you should add reference to jQuery in your .html file which is going to refer the external javascript file containing validation functions.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="<your java script file containing validation functions></script>
Sign up to request clarification or add additional context in comments.

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.