1

I'm trying to run two different scripts, but only one will work at a time. If Code 1 and 2 are on the same page only one works. How can I make them work on the same page?

Code 1

<script src="lib/jquery-1.5.2.min.js"></script>
<script src="lib/jquery.peelback.js"></script>  
<script>
$(function() {
  $('body').peelback({
    adImage  : 'images/peel-ad.png',
    peelImage  : 'images/peel-image.png',
    clickURL : 'http://www.thebestdinosaur.com/',
    smallSize: 150,
    bigSize: 500,
    gaTrack  : true,
    gaLabel  : '#1 Stegosaurus',
    autoAnimate: true
  });
});
</script>

Code 2

<script src="lib/jquery.min.js" type="text/javascript"></script>
<script src="lib/jquery.nivo.slider.pack.js" type="text/javascript"></script>
<script type="text/javascript">
$(window).load(function() {
$('#slider').nivoSlider();
});
</script>
Randell
  • 6,112
  • 6
  • 45
  • 70
user196815
  • 11
  • 2
  • 2
    Only include jQuery once. – Jason P Mar 19 '14 at 03:08
  • 1
    Read about https://api.jquery.com/jQuery.noConflict/ if you really have to use two different versions. See also [Can I use multiple versions of jQuery on the same page?](http://stackoverflow.com/q/1566595/218196) – Felix Kling Mar 19 '14 at 03:12

1 Answers1

1

You can use jQuery.noconflict, so replace your first code with:

<script src="lib/jquery-1.5.2.min.js"></script>
<script src="lib/jquery.peelback.js"></script>  
<script>
var jq152 = jQuery.noConflict(true);
jq152(function($) {
    $('body').peelback({
        adImage: 'images/peel-ad.png',
        peelImage: 'images/peel-image.png',
        clickURL: 'http://www.thebestdinosaur.com/',
        smallSize: 150,
        bigSize: 500,
        gaTrack: true,
        gaLabel: '#1 Stegosaurus',
        autoAnimate: true
    });
});
</script>
Felix
  • 37,892
  • 8
  • 43
  • 55
  • 1
    You removed the the `ready` callback (intentionally?). Just do `jq152(function($) { ... });`. – Felix Kling Mar 19 '14 at 03:15
  • Felix, your code works perfect in IE, but in Firefox only the nivo.slider works. Any ideas? View http://wjfd.org – user196815 Mar 20 '14 at 02:28
  • @user196815 Not sure why but your site works perfect for me in Firefox and Chrome. Try to clear your browser cache. – Felix Mar 20 '14 at 02:33