0

I'm very new to jQuery and I've looked at many problems out there. And mostly might worked for them but not for me. The problem is about using multiple jQuery in the same page. Here is my code in head tag.

<!-- load jQuery 1.8.2) -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<!-- bxSlider Javascript file -->
<script src="assets/scripts/bxslider/jquery.bxslider.min.js"></script>
<!-- bxSlider CSS file -->
<link href="assets/scripts/bxslider/jquery.bxslider.css" rel="stylesheet" />

<script>
var jQuery_1_8_2 = $.noConflict(true);
</script>

<!-- fullBackground -->
<script src="assets/scripts/fullbg/jquery.fullbg.min.js"></script>
<!-- load jQuery 1.5.0 -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>

<script>
var jQuery_1_5_0 = $.noConflict(true);
</script>

I'm so confused what's wrong with this. If I use one of them, it's working but after I put both, it's not working at all. Does any of you have solution for this? Thanks.

12
  • 3
    Why do you need multiple jQuery? This is a very bad idea. Commented Jan 7, 2014 at 17:04
  • 1
    That's because you shouldn't load two jQuery versions. There is no reason you should need two versions. Commented Jan 7, 2014 at 17:04
  • 2
    This is soooo bad, don't use different versions of jQuery in the same "javascript" envrionment Commented Jan 7, 2014 at 17:04
  • @War10ck So if I want to use a plugin that is compatible with jQuery 1.4 but not jQuery 1.9, how do I go about that? Commented Jan 7, 2014 at 17:08
  • One jQuery for slider and another one for fullbackground. I didn't realise that was very bad idea. Should I combine or what should I do? Is one version enough to use for both? Commented Jan 7, 2014 at 17:08

1 Answer 1

1

This should work.

However if the html document is opened from file it won't because the scheme of the first jQuery URL is not defined and so it takes file:// from the parent. As there is probably no local file of this name it does not load and the $ is not defined. Calling the first $.noConflict() function then fails with $ not defined.

Adding a scheme to the first URL fixes this.

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

The reason the scheme is often omitted is so it will use http:// or https:// depending on the what the page is using, which is generally a good thing.

One way to serve a html document over HTTP locally is by running a simple Python HTTP server from the same directory.

python -m SimpleHTTPServer

You can then open your page in your browser at http://localhost:8000/ and your example should work.

Sign up to request clarification or add additional context in comments.

1 Comment

MAGIC! It's pretty clear and understandable! Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.