Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a javascript file and I want to include jquery in this js file. Do you have a suggestion?

share|improve this question
1  
Why do you need to do that? – Sayem Ahmed Sep 21 '11 at 8:33
1  
how about this stackoverflow.com/questions/5577771/… – ayush Sep 21 '11 at 8:34
Because, I want to use jquery library in my javascript file. Do you know another way? – cagin Sep 21 '11 at 8:35
@cagin, another way is to search before asking. :) – bzlm Sep 21 '11 at 8:42
add comment (requires an account with 50 reputation)

3 Answers

up vote 4 down vote accepted

Simply include the JavaScript for jQuery before you include your own JavaScript:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="path/to/your/script.js"></script>

Though others have suggested simply copying and pasting jQuery into your own JavaScript file, it's really better to include jQuery separately from a canonical source as that will allow you to take advantage of the caching that your browser and intermediate servers have done for that file.

share|improve this answer
add comment (requires an account with 50 reputation)

you want to include a js file into a js file... javascript does not have something like a include function but you can load the file with an ajax request. check this out Include JavaScript file inside JavaScript file?

share|improve this answer
+1 for the link – kc2001 Nov 21 '12 at 19:02
add comment (requires an account with 50 reputation)

Just merge the files.

cat jquery.js >> a_javascript_file.js

Or, since you probably want jQuery first:

cat a_javascript_file.js jquery.js > tmp.js;
mv tmp.js a_javascript_file.js
share|improve this answer
Now, that's just mean. :) – bzlm Sep 21 '11 at 8:42
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.