[CiviCRM] How to use JQuery in CiviCRM?

| | 1 min read

In one of form that I created it need some client side dynamic behavior. I did that in a javascript and used JQuery. But it did not worked. I thought that JQuery did not work in CiviCRM.

Actually CiviCRM supports JQuery. But your code should be inside cj(function ( $ ) or CRM.$ section.

See the example.


cj(function ( $ ) {
  $(document).ready(function(){
....
}});

Now my code started working.

We can use CRM.$ also.


CRM.$(function($) {
  // Your code here
});

For more details please refer: http://wiki.civicrm.org/confluence/display/CRMDOC/Javascript+Reference