0

I'm having a problem with this sample code. When I try to execute someFunc(), I get the error: Uncaught TypeError: $.twbsPagination is not a function.

<html>
<head>
<script type='text/javascript' src="~/Scripts/jquery-3.3.1.min.js"></script>
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="~/Scripts/jquery.twbsPagination.js"></script>
</head>

<body>

...

<td>
    <button id="button" onclick="someFunc(); return false;">Display Pages</button>
</td>
<div id="pagination-demo"></div>

...
<script>
   function load() {
       $('#pagination-demo').twbsPagination({  // THIS WORKS.
           totalPages: 35,
           visiblePages: 7,
           onPageClick: function (event, page) {
               $('#page-content').text('Page ' + page);
           }
       });
   }
      
   function someFunc() {
      $.twbsPagination(); // THIS DOESN'T WORK.
   }
}
</script>

</body>
</html>

I've also tried:

function someFunc() {
   $('#pagination-demo').twbsPagination({
           totalPages: 10,
           visiblePages: 7,
           onPageClick: function (event, page) {
               $('#page-content').text('Page ' + page);
           }
       });
   }

This doesn't work, either. I still get the above Uncaught TypeError. How do I fix this? It just doesn't seem to work when called from the onClick event.

1 Answer 1

0

The correct usage of jquery.twbsPagination.js is to provide a selector / list of elements first before calling twbsPagination({ ... }).

In short, this usage is incorrect: $.twbsPagination({ ... }) while this is correct: $('.your-element').twbsPagination({ ... })

Sign up to request clarification or add additional context in comments.

1 Comment

I've tried $('.your-element').twbsPagination({ ... }) already. I still get an error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.