$(...).tagsinput is not a function

aco picture aco · May 14, 2016 · Viewed 13.2k times · Source

I must be missing something simple but I can't see it. I am using the Bootstrap tagsinput plugin and I am trying to follow some of the examples here: http://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/

Here is my code:

<html>
  <head>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/bootstrap.tagsinput/0.4.2/bootstrap-tagsinput.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/bootstrap.tagsinput/0.4.2/bootstrap-tagsinput.min.js"></script>
  </head>
  <body>
    <input id="cities" class="form-control" value="New York,London" data-role="tagsinput" type="text">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script>
      $(function() {
        $('#cities').tagsinput({
          maxTags: 3
        });
      });
    </script>
  </body>
</html>

I am getting the following Javascript error:

tagsinput.html:15 Uncaught TypeError: $(...).tagsinput is not a function

I tried removing data-role="tagsinput" as suggested in this SO answer but the input becomes a regular textbox and the exception still occurs.

What am I doing wrong?

Answer

Ramanlfc picture Ramanlfc · May 14, 2016

you're loading 2 jquery min files in your script tags.

remove the one after bootstrap-tagsinput.min.js or since the 2nd one is newer version load that instead of the 1st one.

http://jsbin.com/xarasebibi/edit?html,output