USharing
开放博客

wordpress jquery

Step 1: Inclusion of jQuery Library

wp_enqueue_script( 'tt-mobile-menu', get_template_directory_uri() .

'/js/mobile-menu.js', array('jquery'), '1.0', true );

Step 2: Structure of JavaScript File

jQuery(document).ready(function()

{

jQuery(#selector) ...

});

Alternate:Wrapping the Code in a Function

If you want to go with default “$” symbol, you can wrap the code within a function as follows –

(function($) {

// Use $() inside of this function

$(#selector) ...

})(jQuery);

Step 3: Ensure that jQuery is Loaded

Sometimes, there are issues because the jQuery is not loaded though included. So to make sure that jQuery is loaded, copy the URL from script src and paste it in the new browser tab. For example: If the script src is this:

<script src="http://code.jquery.com/jquery-1.11.2.min.js" type="text/javascript"></script>

 

来源: https://blog.templatetoaster.com/fix-jquery-is-not-defined-error/

赞(0) 打赏
未经允许不得转载:USharing » wordpress jquery

觉得文章有用就打赏一下文章作者

微信扫一扫打赏