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.
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.
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.
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.
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.
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 ($) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With