Got error TypeError: $ is not a function
Got error TypeError: $ is not a function
gbmapo
Posts: 17Questions: 6Answers: 0
Just added Datables to a Drupal 8 site and tried to use it on View formatted as a table (of course). My settings seem correct: in the generated html, I get this:
<head>
some Drupal CSS stuff
<script src="/core/assets/vendor/modernizr/modernizr.min.js?v=3.3.1">
</script>
<script src="/core/assets/vendor/jquery/jquery.min.js?v=3.2.1">
</script>
<script src="/libraries/DataTables/datatables.min.js?v=1.x">
</script>
<script src="/modules/custom/association/js/LoM.js?v=1.x">
</script>
</head>
<body>
<div>
other Drupal stuff (menus, theme regions...)
<div class="view-content">
<table class="views-table views-view-table cols-8 sticky-enabled" id="ListOfMembers">
<thead>...</thead>
<tbody>...</tbody>
</table>
</div>
</div>
Other Drupal javascript stuff
</body>
In LoM.js, I have coded this:
$(document).ready(function() {
$('#ListOfMembers').DataTable();
} );
So jquery, datables and my initialization seem to be loaded in the right order.
But nothing happens and when I go to the browser console, I get this error:
Any idea why?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I'm not familiar with Drupal but maybe this thread will help:
https://stackoverflow.com/questions/3931529/is-not-a-function-jquery-error
The problem is either your jQuery.min.js is not loading or your environment is setup to not use the
$
for jQuery.Kevin
It helped! I updated LoM.js this way:
And it works!