Using JQuery in Drupal 7

前端 未结 5 625
长情又很酷
长情又很酷 2021-01-30 17:18

I\'m writing my own Drupal 7 module, and like to use JQuery in it.

$(\'#field\').toggle();

But I\'m getting this error:

TypeErr         


        
5条回答
  •  感情败类
    2021-01-30 17:51

    "$ is not a function" is a very common error that you may face while working with jQuery. You can try any answers of given below:

    (function($){
    //your can write your code here with $ prefix
    })(jQuery);
    

    OR

    jQuery(document).ready(function($){
    //Write your code here
    });
    

    Basically this will allow our code to run and use the $ shortcut for JQuery.

提交回复
热议问题