Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Error, Uncaught TypeError Property '$' of object [object Object] is not a function

I'm trying to insert a script in a Joomla module. The script is a percentage loader in JS. I'm had some issues with another js but I finally managed to solve them.

The error i'm getting is:

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

I'm trying to import the Percentage Loader jQuery plugin

And the js code is:

$(function() {
  var $topLoader = $("#dttopLoader").percentageLoader({width: 256, height: 256, controllable : true, progress : 0.5, onProgressUpdate : function(val) {
      $topLoader.setValue(Math.round(val * 100.0));
    }});

  var topLoaderRunning = false;
  $("#dtanimateButton").click(function() {
    if (topLoaderRunning) {
      return;
    }
    topLoaderRunning = true;
    $topLoader.setProgress(0);
    $topLoader.setValue('0kb');
    var kb = 0;
    var totalKb = 999;

    var animateFunc = function() {
      kb += 17;
      $topLoader.setProgress(kb / totalKb);
      $topLoader.setValue(kb.toString() + 'kb');

      if (kb < totalKb) {
        setTimeout(animateFunc, 25);
      } else {
        topLoaderRunning = false;
      }
    }

    setTimeout(animateFunc, 25);

  });
});      

I tried changing the first line from "$(function()..." to "jquery(function()..." as I read many topics on stackoverflow but still can't fix it.

like image 236
manosim Avatar asked Apr 11 '13 13:04

manosim


People also ask

How do I fix uncaught TypeError is not a function?

The TypeError: "x" is not a function can be fixed using the following suggestions: Paying attention to detail in code and minimizing typos. Importing the correct and relevant script libraries used in code. Making sure the called property of an object is actually a function.

What is uncaught type error in JavaScript?

This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the expression did not return a function object.

Is not a function error JavaScript?

The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value is not actually a function.

What is JavaScript TypeError?

The TypeError object represents an error when an operation could not be performed, typically (but not exclusively) when a value is not of the expected type. A TypeError may be thrown when: an operand or argument passed to a function is incompatible with the type expected by that operator or function; or.


1 Answers

There seems to be a similar issue in this SO post here but in WordPress.

You said you are using Joomla. Joomla might also include the jQuery library loaded "no conflict" mode and perhaps the same solution can be applied.

Try replacing this:

$(function() {

With this:

jQuery(document).ready(function ($) {
like image 132
Nope Avatar answered Oct 20 '22 22:10

Nope