Search code examples
javascriptjqueryhtmlslicknav

Multiple javascript/jquery scripts on same webpage


I have a responsive menu and responsive slideshow that requires javascript and jquery but only one works.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="js/responsiveslides.min.js"></script>

<script>
  $(function() {
    $(".rslides").responsiveSlides();
  });
</script>


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="js/jquery.slicknav.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('#menu').slicknav({
        prependTo:"#border-orange"});
});
</script>

The 2nd one works but the first one doesn't. When I switch them over, again, the 2nd one works but the 1st one doesn't. Is there a way to combine the code so that both scripts work or is it a case of "one or the other"?


Solution

  • You're including jQuery twice, just remove the second reference and you can have as many sections of $(document).ready() as you want to :

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src="js/responsiveslides.min.js"></script>
    
    <script>
      $(function() {
        $(".rslides").responsiveSlides();
      });
    </script>
    
    <script src="js/jquery.slicknav.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $('#menu').slicknav({
            prependTo:"#border-orange"});
    });
    </script>