When developing JS scripts for Drupal, the built-in jquery is called in a rather strange way, you need to wrap your functions as though

(function ($) { .... Ф-я }) (jQuery); 

The question itself: Here there is a crest causing a modal window with a form:

  $(function() { $("a[rel]").overlay(function() { var wrap = this.getContent().find("div.wrap"); if (wrap.is(":empty")) { wrap.load(this.getTrigger().attr("href")); } }); }); 

I make out in the image and likeness of it with the fact that I wrote above, but nothing works, while everything works fine without drupal, but when I try to embed it, it doesn't.

Actually, the question is: how to properly execute js-scripts for developing with drupal?

  • 3
    where does drupal? - do4a
  • Actually on Habré was a post about how to write scripts for Drupal, and actually it just worked on the page, and when introduced to the site it stopped, and Drupal at the same time - Rumato

1 answer 1

drupal_add_js('path/to/your/js');

 (function ($) { Drupal.behaviors.yourmodule = { attach: function (context, settings) { // $ здесь можно уже знак долларом пользоваться $('#mymodule_id', context).change(function () { alert('Handler for .change() called.'); }); } }; }(jQuery)); 
  • thank! It is useful! - Rumato