Eutherpy Eutherpy - 3 years ago 146
Javascript Question

Javascript: "is not a function" error

I am trying to use the easyPaginate.js plugin (https://st3ph.github.io/jquery.easyPaginate/) in my code:

index.jsp

<script type="text/javascript" src="./js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="./js/myJs.js"></script>
<script type="text/javascript" src="./js/jquery.easyPaginate.js"></script>
...
<div id="easyPaginate">
<img src="img/demo/surf1.jpg" />
<img src="img/demo/surf2.jpg" />
</div>


myJs.js:

$('#easyPaginate').easyPaginate({
paginateElement: 'img',
elementsPerPage: 3,
effect: 'climb'
});


but I am getting the following error:


Uncaught TypeError: $(...).easyPaginate is not a function
at myJs.js:20

Answer Source

You should declare scripts in this order:

<script type="text/javascript" src="./js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="./js/jquery.easyPaginate.js"></script>
<script type="text/javascript" src="./js/myJs.js"></script>

As the error says, easyPaginate method can't be found in myJs script.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download