title: Uncaught TypeError: undefined is not a function - typeahead.js
body: <p>I'm trying to get a a basic <a href="https://twitter.github.io/typeahead.js/examples/" rel="noreferrer">typeahead.js example</a> to work. The example works if I create it in a separate HTML file as below.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script type="text/javascript" src="/static/js/jquery-1.9.1.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="/static/js/bootstrap.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="/static/js/typeahead.bundle.min.js"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
      $(document).ready(function() {
          var substringMatcher = function(strs) {
            return function findMatches(q, cb) {
              var matches, substringRegex;
  
              // an array that will be populated with substring matches
              matches = [];
  
              // regex used to determine if a string contains the substring `q`
              substrRegex = new RegExp(q, 'i');
  
              // iterate through the pool of strings and for any string that
              // contains the substring `q`, add it to the `matches` array
              $.each(strs, function(i, str) {
                if (substrRegex.test(str)) {
                  // the typeahead jQuery plugin expects suggestions to a
                  // JavaScript object, refer to typeahead docs for more info
                  matches.push({ value: str });
                }
              });
  
              cb(matches);
            };
          };
  
          var djs = ['Hardwell', 'Armin van Buuren', 'Avicii', 'Tiesto', 'David Guetta', 
                     'Dimitri Vegas &amp; Like Mike', 'Nicky Romero', 'Steve Aoki', 'Afrojack', 
                     'Dash Berlin', 'Skrillex', 'Deadmau5', 'Alesso', 'W&amp;W', 'Calvin Harris', 
                     'NERVO', 'Above &amp; Beyond', 'Sebastian Ingrosso', 'Axwell', 'Aly &amp; Fila', 
                     'Markus Schulz', 'Daft Punk', 'Headhunterz', 'Zedd', 'Knife Party', 
                     'Swedish House Mafia', 'Showtek', 'Andrew Rayel', 'Fedde Le Grand', 
                     'Dyro', 'Laidback Luke', 'Paul van Dyk', 'ATB', 'Angerfist', 'Dada Life',
                     'Kaskade', 'Frontliner', 'Steve Angello', 'Sander Van Doorn', 
                     'Martin Garrix', 'Porter Robinson', 'Ferry Corsten', 'Chuckie', 
                     'Krewella', 'Coone', 'Carl Cox', 'Bobina', 'Omnia', 'Orjan Nilsen', 
                     'Zatox', 'Gareth Emery', 'Bingo Players', 'Infected Mushroom', 
                     'Eric Prydz', 'Tommy Trash', 'Wildstylez', 'Arty', 'R3hab', 'Madeon', 
                     'Vicetone', 'Brennan Heart', 'DJ Feel', 'Gunz For Hire', 'Diplo', 
                     'Tenishia', 'Noisecontrollers', 'Mike Candys', 'DJ Antoine', 
                     'Quentin Mosimann', 'Project 46', 'Blasterjaxx', 'D-Block &amp; S-te-Fan', 
                     'Dillon Francis', 'Dannic', 'Adaro', 'Richie Hawtin', 'Martin Solveig', 
                     'Felguk', 'Myon &amp; Shane 54', 'Cosmic Gate', 'Heatbeat', "John O'Callaghan", 
                     'Wasted Penguinz', 'Tiddey', 'Skazi', 'Da Tweekaz', 'Tenashar', 
                     'Bob Sinclar', 'Benny Benassi', 'Stafford Brothers', 'DJ BL3ND', 
                     'Paul Oakenfold', 'Mat Zo', 'Diego Miranda', 'DJs From Mars', 'Matt Darey',
                     'UMEK', 'Solarstone', 'Ummet Ozcan', 'Ran-D', 'Disclosure', 'Rudimental',
                     'Flux Pavilion', 'Nero', 'Datsik', 'Moby', 'Zeds Dead', 'The Prodigy',
                     'Bassnectar', 'Adventure Club', 'Dirty South', 'Borgore', 'Modestep', 
                     'Bonobo', 'Feed Me', 'Flosstradamus', 'The Glitch Mob', 'Rusko',
                     'Kill The Noise','Fatboy Slim', 'Zomboy', 'A-Trak', 'James Blake', 
                     'Morgan Page', 'The Bloody Beetroots', 'Quintino', 'Wolfgang Gartner', 
                     'Bakermat', 'M83', 'Pretty Lights', 'Cedric Gervais', 
                     'Sunnery James &amp; Ryan Marciano', 'Baauer', 'Danny Avila', 'Justice', 
                     'Seven Lions', 'Royksopp', 'Bondax', 'Zero 7', 'Lemaitre', 'Noisia', 
                     'Gramatik', 'Thomas Gold', 'Basement Jaxx', 'Aphex Twin', 'Four Tet', 
                     'Flying Lotus', 'Sidney Samson', 'Paul Kalkbrenner', 'Boards Of Canada', 
                     'Maya Jane Coles', 'Groove Armada', 'Juan Magan', 'Chase &amp; Status', 'BT', 
                     'Digitalism', 'Mount Kimbie', 'Benga', 'Audien', 'Bassjackers', 
                     'The Chainsmokers', 'DVBBS', 'Pete Tong', 'Deorro', 'DJ Snake', 
                     'Don Diablo', 'Pendulum', 'Chris Lake', 'Dzeko &amp; Torres', 'Zhu'
          ];
  
          $('#dj-search .typeahead').typeahead({
            hint: true,
            highlight: true,
            minLength: 1
          },
          {
            name: 'djs',
            displayKey: 'value',
            source: substringMatcher(djs)
          });
      }); 
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;form id="search_bar" class="navbar-form navbar-left"&gt;
      &lt;div class="form-group" id="dj-search"&gt;
          &lt;input type="text" class="form-control typeahead" placeholder="Search favourite DJs" autocomplete="off"&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>If I try to get the same code to work for my existing HTML template, I keep on getting the error</p>
  
  <p><code>Uncaught TypeError: undefined is not a function</code></p>
  
  <p>on the line</p>
  
  <p><code>$('#dj-search .typeahead').typeahead({</code></p>
  
  <p>What could be causing this error?</p>
  
  <p>Below is my full HTML</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;title&gt;EDM Hunters | Top 100 DJs | Discover the Best of Electronic Dance Music&lt;/title&gt;
  
          &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
          &lt;meta name="description" content="Listen to, vote on and discover the Top Electronic Dance Music Songs by the Top DJs of the world"&gt;
          &lt;meta property="og:image" content="/static/img/edmlogo.jpg"/&gt;
  
          &lt;link rel="shortcut icon" href="/static/img/favicon.ico"&gt;
          &lt;link href="/static/css/bootstrap.min.css" rel="stylesheet" type='text/css'/&gt;
          &lt;link href="/static/css/bootstrap-theme.min.css" rel="stylesheet" type='text/css'/&gt;
          &lt;link href="/static/css/style.css" rel="stylesheet" type='text/css'/&gt;
  
          &lt;script type="text/javascript" src="/static/js/jquery-1.9.1.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="/static/js/bootstrap.min.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="/static/js/typeahead.bundle.min.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-53a4066858ab24f0"&gt;&lt;/script&gt;
  
          &lt;script type="text/javascript"&gt;
              $(document).ready(function() {
                  var substringMatcher = function(strs) {
                    return function findMatches(q, cb) {
                      var matches, substringRegex;
  
                      // an array that will be populated with substring matches
                      matches = [];
  
                      // regex used to determine if a string contains the substring `q`
                      substrRegex = new RegExp(q, 'i');
  
                      // iterate through the pool of strings and for any string that
                      // contains the substring `q`, add it to the `matches` array
                      $.each(strs, function(i, str) {
                        if (substrRegex.test(str)) {
                          // the typeahead jQuery plugin expects suggestions to a
                          // JavaScript object, refer to typeahead docs for more info
                          matches.push({ value: str });
                        }
                      });
  
                      cb(matches);
                    };
                  };
  
                  var djs = ['Hardwell', 'Armin van Buuren', 'Avicii', 'Tiesto', 'David Guetta', 
                             'Dimitri Vegas &amp; Like Mike', 'Nicky Romero', 'Steve Aoki', 'Afrojack', 
                             'Dash Berlin', 'Skrillex', 'Deadmau5', 'Alesso', 'W&amp;W', 'Calvin Harris', 
                             'NERVO', 'Above &amp; Beyond', 'Sebastian Ingrosso', 'Axwell', 'Aly &amp; Fila', 
                             'Markus Schulz', 'Daft Punk', 'Headhunterz', 'Zedd', 'Knife Party', 
                             'Swedish House Mafia', 'Showtek', 'Andrew Rayel', 'Fedde Le Grand', 
                             'Dyro', 'Laidback Luke', 'Paul van Dyk', 'ATB', 'Angerfist', 'Dada Life',
                             'Kaskade', 'Frontliner', 'Steve Angello', 'Sander Van Doorn', 
                             'Martin Garrix', 'Porter Robinson', 'Ferry Corsten', 'Chuckie', 
                             'Krewella', 'Coone', 'Carl Cox', 'Bobina', 'Omnia', 'Orjan Nilsen', 
                             'Zatox', 'Gareth Emery', 'Bingo Players', 'Infected Mushroom', 
                             'Eric Prydz', 'Tommy Trash', 'Wildstylez', 'Arty', 'R3hab', 'Madeon', 
                             'Vicetone', 'Brennan Heart', 'DJ Feel', 'Gunz For Hire', 'Diplo', 
                             'Tenishia', 'Noisecontrollers', 'Mike Candys', 'DJ Antoine', 
                             'Quentin Mosimann', 'Project 46', 'Blasterjaxx', 'D-Block &amp; S-te-Fan', 
                             'Dillon Francis', 'Dannic', 'Adaro', 'Richie Hawtin', 'Martin Solveig', 
                             'Felguk', 'Myon &amp; Shane 54', 'Cosmic Gate', 'Heatbeat', "John O'Callaghan", 
                             'Wasted Penguinz', 'Tiddey', 'Skazi', 'Da Tweekaz', 'Tenashar', 
                             'Bob Sinclar', 'Benny Benassi', 'Stafford Brothers', 'DJ BL3ND', 
                             'Paul Oakenfold', 'Mat Zo', 'Diego Miranda', 'DJs From Mars', 'Matt Darey',
                             'UMEK', 'Solarstone', 'Ummet Ozcan', 'Ran-D', 'Disclosure', 'Rudimental',
                             'Flux Pavilion', 'Nero', 'Datsik', 'Moby', 'Zeds Dead', 'The Prodigy',
                             'Bassnectar', 'Adventure Club', 'Dirty South', 'Borgore', 'Modestep', 
                             'Bonobo', 'Feed Me', 'Flosstradamus', 'The Glitch Mob', 'Rusko',
                             'Kill The Noise','Fatboy Slim', 'Zomboy', 'A-Trak', 'James Blake', 
                             'Morgan Page', 'The Bloody Beetroots', 'Quintino', 'Wolfgang Gartner', 
                             'Bakermat', 'M83', 'Pretty Lights', 'Cedric Gervais', 
                             'Sunnery James &amp; Ryan Marciano', 'Baauer', 'Danny Avila', 'Justice', 
                             'Seven Lions', 'Royksopp', 'Bondax', 'Zero 7', 'Lemaitre', 'Noisia', 
                             'Gramatik', 'Thomas Gold', 'Basement Jaxx', 'Aphex Twin', 'Four Tet', 
                             'Flying Lotus', 'Sidney Samson', 'Paul Kalkbrenner', 'Boards Of Canada', 
                             'Maya Jane Coles', 'Groove Armada', 'Juan Magan', 'Chase &amp; Status', 'BT', 
                             'Digitalism', 'Mount Kimbie', 'Benga', 'Audien', 'Bassjackers', 
                             'The Chainsmokers', 'DVBBS', 'Pete Tong', 'Deorro', 'DJ Snake', 
                             'Don Diablo', 'Pendulum', 'Chris Lake', 'Dzeko &amp; Torres', 'Zhu'
                  ];
  
                  $('#dj-search .typeahead').typeahead({
                    hint: true,
                    highlight: true,
                    minLength: 1
                  },
                  {
                    name: 'djs',
                    displayKey: 'value',
                    source: substringMatcher(djs)
                  });
              }); 
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div id="edmhunters_body"&gt;
              &lt;div class="navbar navbar-inverse navbar-fixed-top" role="navigation"&gt;
                  &lt;div class="container"&gt;
                      &lt;div class="navbar-header"&gt;
                          &lt;button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"&gt;
                              &lt;span class="sr-only"&gt;Toggle navigation&lt;/span&gt;
                              &lt;span class="icon-bar"&gt;&lt;/span&gt;
                              &lt;span class="icon-bar"&gt;&lt;/span&gt;
                              &lt;span class="icon-bar"&gt;&lt;/span&gt;
                          &lt;/button&gt;
                          &lt;a class="navbar-brand" href="#"&gt;&lt;img id="edm" src="/static/img/edmlogo.png" alt="EDM Hunters logo"/&gt;&lt;/a&gt;
                      &lt;/div&gt;
                      &lt;div class="collapse navbar-collapse"&gt;
                          &lt;ul class="nav navbar-nav"&gt;
                              &lt;li class="active"&gt;
                                  &lt;a href="#"&gt;&lt;strong&gt;Top 100 DJs&lt;/strong&gt;&lt;/a&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;a href="/explore/"&gt;&lt;strong&gt;Explore More DJs&lt;/strong&gt;&lt;/a&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;a href="/genres/"&gt;&lt;strong&gt;Browse by Genres&lt;/strong&gt;&lt;/a&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;a href="/monthly/"&gt;&lt;strong&gt;Monthly Top Songs&lt;/strong&gt;&lt;/a&gt;
                              &lt;/li&gt;
                              &lt;li&gt;
                                  &lt;a href="/trending/"&gt;&lt;strong&gt;Trending Songs&lt;/strong&gt;&lt;/a&gt;
                              &lt;/li&gt;
                          &lt;/ul&gt;
                          &lt;form id="search_bar" class="navbar-form navbar-left"&gt;
                              &lt;div class="form-group" id="dj-search"&gt;
                                  &lt;input type="text" class="form-control typeahead" placeholder="Search favourite DJs" autocomplete="off"&gt;
                              &lt;/div&gt;
                          &lt;/form&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="container"&gt;
                  &lt;div class="jumbotron" style="color:white;background-color:#252525;"&gt;
                      &lt;h1&gt;EDM Hunters&lt;/h1&gt;
                      &lt;p&gt;EDM Hunters is a place where you can listen to and discover the Top Electronic Dance Music Songs by the Top DJs of the world. Don't agree with a list? Vote for your favourite song. What's your #1?&lt;/p&gt;
                      &lt;p&gt;&lt;a class="btn btn-primary btn-lg" role="button" href="/faq/"&gt;Learn more&lt;/a&gt;&lt;/p&gt;
                  &lt;/div&gt;
                  &lt;div class="col-md-11"&gt;
      &lt;div class="row dj_row"&gt;
          &lt;div class="col-md-2 col-md-offset-1 text-center dj-md-2"&gt;
              &lt;p&gt;&lt;strong&gt;#1 Hardwell&lt;/strong&gt;&lt;/p&gt;
              &lt;a href="/hardwell/"&gt;&lt;img src="/static/img/1.jpg" class="img-rounded dj_img" alt="Hardwell"/&gt;&lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="col-md-2 text-center dj-md-2"&gt;
              &lt;p&gt;&lt;strong&gt;#2 Armin van Buuren&lt;/strong&gt;&lt;/p&gt;
              &lt;a href="/armin-van-buuren/"&gt;&lt;img src="/static/img/2.jpg" class="img-rounded dj_img" alt="Armin van Buuren"/&gt;&lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="col-md-2 text-center dj-md-2"&gt;
              &lt;p&gt;&lt;strong&gt;#3 Avicii&lt;/strong&gt;&lt;/p&gt;
              &lt;a href="/avicii/"&gt;&lt;img src="/static/img/3.jpg" class="img-rounded dj_img" alt="Avicii"/&gt;&lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="col-md-2 text-center dj-md-2"&gt;
              &lt;p&gt;&lt;strong&gt;#4 Tiesto&lt;/strong&gt;&lt;/p&gt;
              &lt;a href="/tiesto/"&gt;&lt;img src="/static/img/4.jpg" class="img-rounded dj_img" alt="Tiesto"/&gt;&lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="col-md-2 text-center dj-md-2"&gt;
              &lt;p&gt;&lt;strong&gt;#5 David Guetta&lt;/strong&gt;&lt;/p&gt;
              &lt;a href="/david-guetta/"&gt;&lt;img src="/static/img/5.jpg" class="img-rounded dj_img" alt="David Guetta"/&gt;&lt;/a&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="row dj_row"&gt;
          &lt;div class="col-md-2 col-md-offset-1 text-center dj-md-2"&gt;
              &lt;p&gt;&lt;strong&gt;#6 Dimitri Vegas &amp;amp; Like Mike&lt;/strong&gt;&lt;/p&gt;
              &lt;a href="/dimitri-vegas-and-like-mike/"&gt;&lt;img src="/static/img/6.jpg" class="img-rounded dj_img" alt="Dimitri Vegas &amp;amp; Like Mike"/&gt;&lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="col-md-2 text-center dj-md-2"&gt;
              &lt;p&gt;&lt;strong&gt;#7 Nicky Romero&lt;/strong&gt;&lt;/p&gt;
              &lt;a href="/nicky-romero/"&gt;&lt;img src="/static/img/7.jpg" class="img-rounded dj_img" alt="Nicky Romero"/&gt;&lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="col-md-2 text-center dj-md-2"&gt;
              &lt;p&gt;&lt;strong&gt;#8 Steve Aoki&lt;/strong&gt;&lt;/p&gt;
              &lt;a href="/steve-aoki/"&gt;&lt;img src="/static/img/8.jpg" class="img-rounded dj_img" alt="Steve Aoki"/&gt;&lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="col-md-2 text-center dj-md-2"&gt;
              &lt;p&gt;&lt;strong&gt;#9 Afrojack&lt;/strong&gt;&lt;/p&gt;
              &lt;a href="/afrojack/"&gt;&lt;img src="/static/img/9.jpg" class="img-rounded dj_img" alt="Afrojack"/&gt;&lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="col-md-2 text-center dj-md-2"&gt;
              &lt;p&gt;&lt;strong&gt;#10 Dash Berlin&lt;/strong&gt;&lt;/p&gt;
              &lt;a href="/dash-berlin/"&gt;&lt;img src="/static/img/10.jpg" class="img-rounded dj_img" alt="Dash Berlin"/&gt;&lt;/a&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="endless_container"&gt;
          &lt;a class="endless_more" href="/?page=2"
              rel="page"&gt;more&lt;/a&gt;
          &lt;div class="endless_loading" style="display: none;"&gt;&lt;img src="/static/img/ajax-loader.gif" style="margin-left:535px;margin-top:25px;" alt="loading"/&gt;&lt;/div&gt;
      &lt;/div&gt;
                      &lt;script src="/static/js/jquery-1.9.1.js"&gt;&lt;/script&gt;
                      &lt;script src="/static/js/endless-pagination.js"&gt;&lt;/script&gt;
                      &lt;script&gt;
                          $.endlessPaginate({
                              paginateOnScroll: true,
                              paginateOnScrollMargin: 130
                          });
                      &lt;/script&gt; 
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="push"&gt;&lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="footer"&gt;
              &lt;div id="disclaimer"&gt;
                  &lt;p&gt;*Rankings according to &lt;a href="http://www.djmag.com/top100?year=2013" target="_blank"&gt;DJ Mag Top 100 DJs 2013&lt;/a&gt;&lt;/p&gt;
              &lt;/div&gt;  
              &lt;footer&gt;
                  &lt;span id=copy class='pull-right'&gt;&lt;strong&gt;&amp;copy; EDM Hunters 2014&lt;/strong&gt;&lt;/span&gt;
                  &lt;a href="/contact/" id="contactus" class='pull-right'&gt;Contact us&lt;/a&gt;
                  &lt;a href="/faq/" id="faq" class="pull-right"&gt;FAQ&lt;/a&gt;
                  &lt;div class="clearfix"&gt;&lt;/div&gt;
              &lt;/footer&gt;   
          &lt;/div&gt;
          &lt;script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-53a4066858ab24f0"&gt;&lt;/script&gt;
          &lt;script&gt;
              (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
                  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
                  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
              })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
              ga('create', 'UA-47063606-1', 'edmhunters.com');
              ga('send', 'pageview');
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>