Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve the jQuery.Deferred exception: $(...).treemenu(...).openActive is not a function TypeError?

When including a jQuery function in my JavaScript code, I get the following console error in Chrome: jQuery.Deferred exception: $(...).... is not a function TypeError

I went through virtually all existing questions related to this issue on Stackoverflow, but couldn't get rid of the error.

First I thought the error was caused by loading jQuery itself, so I tried loading jQuery like this in functions.php:

function add_jqmigrate_script() {
        wp_register_script('jquery', 'https://code.jquery.com/jquery-3.5.1.min.js', false, true);
        wp_enqueue_script('jquery');
        wp_enqueue_script( 'jqm-script2', 'https://code.jquery.com/jquery-migrate-3.3.1.min.js',array ('jquery'), false, true);
}
add_action( 'wp_enqueue_scripts', 'add_jqmigrate_script' );

Then, I tried loading it within the JavaScript file directly, as follows:

<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://code.jquery.com/jquery-migrate-3.3.1.min.js"></script>

There is no difference, the error remains.

Then, I tried different variations of the jQuery function, as follows. All of the variations do not change the error message. Interestingly, the script appears to actually work, see link. I am grateful for any hints or suggestions how to solve this. Thanks!

1)

jQuery(function(){
            $(".tree").treemenu({delay:500}).openActive();
});
jQuery(function($){
            $(".tree").treemenu({delay:500}).openActive();
});
jQuery(function($) {
  $(function() {
            $(".tree").treemenu({delay:500}).openActive();
  });
});
jQuery(function(){
        $(document).ready(function() {
            $(".tree").treemenu({delay:500}).openActive();
        });
});
like image 321
F.Marks Avatar asked Dec 31 '25 08:12

F.Marks


1 Answers

It looks like there's some mix up in the versions vs out-dated examples.

In v0.4 there's an $.fn.openActive extension and the demo uses v0.4. This has been removed in v0.6 (or earlier) and replaced with the openActive:true option.

From changelog

2016-11-24

fix styles
don't touch tree-empty el when use closeOther
move fn.openActive() code to fn.treemenu()

The code for your website (using v0.6) should be (from github page):

$(function(){
  $(".tree").treemenu({delay:500, openActive:true});
});
like image 80
freedomn-m Avatar answered Jan 02 '26 22:01

freedomn-m



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!