I've got the error 'Uncaught TypeError: jQuery(...).appear is not a function drupal' when trying to use the script below:

content of script.js:

Drupal.behaviors.basic = {
   attach: function (context, settings) {
     (function ($) {
          jQuery('.hero').each(function() {
            jQuery(this).appear(function() {
              var $endNum = parseInt(jQuery(this).find('.number').text());
                from: 0,
                to: $endNum,
                speed: 4000,
                refreshInterval: 60,
                formatter: function (value, options) {
                  value = value.toFixed(options.decimals);
                  value = value.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
                  return value;
            },{accX: 0, accY: 0});

the html:

<div class="hero">
  <div class="number">1,234</div>

Here is how I would debug this issue.

  1. Check if your jQuery object is attached to the global window object. You can do this by typing window.jQuery on your browser console. If this returns 'Undefined' then the issue is with the reference to the jquery library.

  2. Make sure that the jQuery library is loading properly. Inspect your Network tab in your browser to find this out.

  3. Make sure your js has - core/jquery as a dependency i.e.

        js/myjs.js: {}
         - core/jquery

Also, you do not need to use jQuery after you pass 'jQuery' object from the global scope into your IIFE. You should just use '$'. Look at this article for more info.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.