admin管理员组

文章数量:1426631

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', '.5.1.min.js', false, true);
        wp_enqueue_script('jquery');
        wp_enqueue_script( 'jqm-script2', '.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=".5.1.min.js"></script>
<script src=".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();
        });
});

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./jquery-3.5.1.min.js', false, true);
        wp_enqueue_script('jquery');
        wp_enqueue_script( 'jqm-script2', 'https://code.jquery./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./jquery-3.5.1.min.js"></script>
<script src="https://code.jquery./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();
        });
});
Share Improve this question edited Oct 9, 2020 at 16:20 fdomn-m 28.7k8 gold badges39 silver badges67 bronze badges asked Oct 9, 2020 at 16:06 F.MarksF.Marks 3191 gold badge5 silver badges14 bronze badges 3
  • 1 Is there something else in the $(...)....? like $(...).error is not a function (just an example)? – fdomn-m Commented Oct 9, 2020 at 16:16
  • Yes, the full text of the yellow warning in the Chrome console is as follows: jQuery.Deferred exception: $(...).treemenu(...).openActive is not a function TypeError: $(...).treemenu(...).openActive is not a function – F.Marks Commented Oct 9, 2020 at 16:17
  • The actual error message (red) says: Uncaught TypeError: $(...).treemenu(...).openActive is not a function – F.Marks Commented Oct 9, 2020 at 16:19
Add a ment  | 

1 Answer 1

Reset to default 1

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});
});

本文标签: