0

For some reason my lightgallery is not working. I added it the same way I always do and all javascript files are included after Jquery.

I get this message in the console:

Uncaught TypeError: $ is not a function
    at product-1.html:433
(anonymous) @ product-1.html:433

Which points to:

<script type="text/javascript">
    $(document).ready(function($) {
        $("#lightgallery").lightGallery();
    });
</script>

All files are correctly loaded, I checked in the network tab.

What could be the problem and how can I fix it? Maybe there is a conflict somewhere? Can I wrap it in a function to make it work?

My js files:

enter image description here

Eric
  • 95,302
  • 53
  • 242
  • 374
twan
  • 2,450
  • 10
  • 32
  • 92
  • Look in the console network tab to see if jQuery is loading and only loading one version – mplungjan Jan 10 '17 at 12:14
  • is there more code in product-1.html? its complaining about something at line 433 – hairmot Jan 10 '17 at 12:15
  • @mplungjan Yes it's only loaded once. – twan Jan 10 '17 at 12:18
  • Try to replace your js/jQuery.js with https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js – Rahul Jan 10 '17 at 12:20
  • @hairmot No it's pointing to the lightgallery code. The part I highlighted at the bottom of the image. – twan Jan 10 '17 at 12:20
  • @VforVendetta I still have the same error even with the CDN loaded. – twan Jan 10 '17 at 12:22
  • remove $ from $(document).ready(function()), and check – Rahul Jan 10 '17 at 12:24
  • @VforVendetta Then the error is: `document.ready is not a function` – twan Jan 10 '17 at 12:25
  • 2
    Try commenting all js files except jquery and comment google map related code for a while and check – Rahul Jan 10 '17 at 12:26
  • @VforVendetta Thanks, it works when I remove bootstrap.js Weird, never would've thought that would cause a conflict. – twan Jan 10 '17 at 12:28
  • You are welcome !!. And replace your google map script with https://maps.googleapis.com/maps/api/js?key=AIzaSyAa5j5PXOoThi9oSiADE6wzQLNbstY3Q-g and then check. There is no api key included in your script, but iff map not working – Rahul Jan 10 '17 at 12:30
  • Check of the bootstrap version matches the jQuery. They should work fine together – mplungjan Jan 10 '17 at 12:41

4 Answers4

4

in the head

<link href="https://cdn.rawgit.com/sachinchoolur/lightgallery.js/master/dist/css/lightgallery.css" rel="stylesheet">

your html content

<div id="lightgallery">
  <a href="img/img1.jpg">
      <img src="img/thumb1.jpg" />
  </a>
  <a href="img/img2.jpg">
      <img src="img/thumb2.jpg" />
  </a>
</div>

in the body include light gallery js files after jquery

<script src="https://cdn.rawgit.com/sachinchoolur/lightgallery.js/master/dist/js/lightgallery.js"></script>
<script src="https://cdn.rawgit.com/sachinchoolur/lg-pager.js/master/dist/lg-pager.js"></script>
<script src="https://cdn.rawgit.com/sachinchoolur/lg-autoplay.js/master/dist/lg-autoplay.js"></script>
<script src="https://cdn.rawgit.com/sachinchoolur/lg-fullscreen.js/master/dist/lg-fullscreen.js"></script>
<script src="https://cdn.rawgit.com/sachinchoolur/lg-zoom.js/master/dist/lg-zoom.js"></script>
<script src="https://cdn.rawgit.com/sachinchoolur/lg-hash.js/master/dist/lg-hash.js"></script>
<script src="https://cdn.rawgit.com/sachinchoolur/lg-share.js/master/dist/lg-share.js"></script>
<script>
   lightGallery(document.getElementById('lightgallery'));
</script>

This really works for me.

Ozal Zarbaliyev
  • 566
  • 6
  • 22
0

Clearing browser cache may help sometimes. Or narrow down your problem by loading one by one starting with jquery.

tslin
  • 83
  • 1
  • 8
0

This solves the problem :

<script>
   lightGallery(document.getElementById('lightgallery'));
</script>
london_utku
  • 1,070
  • 2
  • 16
  • 36
-1

1.Check your maps api js link like https://developers.google.com/maps/api/js this is correct or not 2.Press Ctrl+Shift+Del button at a same time and clear caches and cookies

Keshan Nageswaran
  • 8,060
  • 3
  • 28
  • 45
skvj
  • 103
  • 1
  • 2
  • 9