-2

I'm using this a tutorial from Hackernoon, and I'm getting the error:

jQuery.fn.sortDomElements = (function() {
^

ReferenceError: jQuery is not defined

in the app.js file. I think it is because for some reason the app.js and the index.html file are not linked together. In the index.html file, the js file and jquery script are included. (link to app.js file)

I tried moving up the three script source lines (428-430 index.html) up in the code, to ensure that theyre being included before the page is loaded, but that did not work.

Both the index.html file and the app.js file are the same for me as they are in the example repo.

this is app.js line 8.

// Make a jQuery sort for the chat log based on message timetoken 
(tt)
jQuery.fn.sortDomElements = (function() {
    return function(comparator) {
        return Array.prototype.sort.call(this, 
comparator).each(function(i) {
              this.parentNode.appendChild(this);
        });
    };
})();
Anna Nevison
  • 2,709
  • 6
  • 21
Eric N.
  • 17
  • 1

2 Answers2

2

probaly you are missing some file that's why it throw an error, you should include your jquery in all pages you will to use

also your function should be like this

jQuery.fn.sortDomElements = (function() {

});
Otávio Barreto
  • 1,536
  • 3
  • 16
  • 35
-1

That error can only be caused by one of three things:

  • Your JavaScript file is not being properly loaded into your page You have a botched version of jQuery.

  • This could happen because someone edited the core file, or a plugin may have overwritten the $ variable.

  • You have JavaScript running before the page is fully loaded, and as such, before jQuery is fully loaded.

Kindly take a look at this question and find fixes Post

Emmanuel
  • 407
  • 3
  • 13