-3

i got an issue with tagit plugin, I can't use it I always got the error $(...).tagit is not a function. Jquery and Jquery Ui are included in my footer and tagit is included in the body. I have jquery ui 1.12.0 min and jquery 2.2.4 min. So if anyone already got this error with this plugin or any other plugin I could use some help. Thanks

I have my main page which include the javascript so:

<ul id="tags">
    <!-- Existing list items will be pre-added to the tags -->
    <li>Tags</li>
</ul>
<script src="<?php echo asset_url("js/ActiviteComplet.js");?>" type="text/javascript" charset="utf-8"></script>

And ActiviteComplet.js:

window.addEventListener('load', initEventHandler, false);

function initEventHandler()
{
    var availableTags = [
        "testa",
        "btest"
    ];
    $("#tags").tagit({
        autocomplete: {delay: 0, minLength: 2, source: availableTags}
    });
}

And finally everything else is included in my footer:

<script type="text/javascript" src="<?php echo asset_url("js/jquery-2.2.4.min.js"); ?>"></script>
<script type="text/javascript" src="<?php echo asset_url("js/jquery-ui.min.js"); ?>"></script>
<script type="text/javascript" src="<?php echo asset_url("js/bootstrap.min.js"); ?>"></script>
<script src="<?php echo asset_url("js/tag-it.js");?>" type="text/javascript" charset="utf-8"></script>

Console error output:

ActiviteComplet.js:9 Uncaught TypeError: $(...).tagit is not a functioninitEventHandler @ ActiviteComplet.js:9
Remi Hirtz
  • 134
  • 3
  • 16

1 Answers1

4

Check a few things:

  1. jQuery is included
  2. Tagit library is included
  3. jQuery is included before Tagit plugin
  4. jQuery is not included more than once

EDIT jQuery UI is also required as it's a dependency of tagit as pointed out by @Bob Kaufman.

Mohit Bhardwaj
  • 9,650
  • 3
  • 37
  • 64