0

I'm trying to use a jquery ticker in my website and this is the code: http://cektkp.com/twittermarquee/twitmarquee.js and I'm getting these errors:

1) Uncaught TypeError: Cannot call method 'extend' of undefined:

window.twttr.bounds = window.twttr.bounds || {};
   $.extend(twttr.bounds, {
      Bounds: function (b, d, c, a) {
        this.x = b;
        this.y = d;
        this.width = c;
        this.height = a
      }
});

2) Uncaught TypeError: Property '$' of object [object Object] is not a function (line 37)

 function loadTrendDescriptions() {
    $("#trends a").each(function () {
        var A = $(this);
        var C = A.parent().find("em");
        if (C.length) {
            var B = A.text();
            var D = C.text().replace(new RegExp(B.replace(/([^\w])/gi, "\\$1"), "gi"), "<strong>" + B + "</strong>");
            var E = A.attr("title").length ? A.attr("title") : A.attr("name");page.trendDescriptions[E] = [B, D]
        }
    })
}

I've fixed many other problems I was getting but these are the ones I just can't understand how to fix. Please help me out!

1 Answer 1

1

You are attempting to use jQuery before it's loaded.

You should place that code inside your ready function:

$(document).ready(function () {
    // place code here
});

Although to be really Drupal-friendly, you should use Drupal's behaviors.

2
  • I added this at the beginning of the file. I'm not getting the second error but the 'Uncaught TypeError: Cannot call method 'extend' of undefined:' stays. (function ($, Drupal, window, document, undefined) { Drupal.behaviors.stocksTicker = { attach: function( context, settings ) { page.trendDescriptions = {}; loadTrendDescriptions(); } } })(jQuery, Drupal, this, this.document); Jul 13, 2013 at 1:30
  • Could that be because this code is using jQuery to load jQuery? Or am I misunderstanding?
    – bitfed
    Oct 20, 2013 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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