1

Added jquery library, it works fine, but when i click on node edit, jquery does not work for this page. I need to style some inputs inside this edit page. I am using theme zen. For example i want to change color of edit-title

(function($) {
$(document).ready(function(){

    $('#edit-title').css('color', 'red');

  });
})(jQuery);

not working. Its loaded i see in firebug. But any code does not work(only inside edit or admin menus).

  • What do you mean by added jquery library. It is already included in the Drupal install. Did you want to update the library ?? if so the correct way of doing it is using drupal.org/project/jquery_update – junedkazi Oct 18 '12 at 21:33
  • added script not library sorry – Petro Popelyshko Oct 18 '12 at 21:47
  • Try using the jQuery over the $ syntax. In other words, jQuery(document).ready(function() { jQuery('#edit-title') and so on. – Cyclonecode Oct 18 '12 at 21:49
3

In the firebug(any) console, try jQuery('#edit-title').css('color', 'red'); it should work or something with the css is wrong.

For Drupal you're really supposed to use something like this to do on document load:

(function ($) {
  Drupal.behaviors.exampleModule = {
    attach: function (context, settings) {
      $('.example', context).click(function () {
        $(this).next('ul').toggle('show');
      });
    }
  };
})(jQuery);

Check out Managing JavaScript in Drupal 7, and search for "behaviors".

@ krister.. The code is a function where the $ variable is jQuery. So in most languages you create function and declare variables that you want passed into it. Well in JavaScript you can create that in one line.

function some_function(tmpVar){ alert(tmpVar); }
some_function("Woot!");

You can wrap the function side in ()s and it still works
( some_function )("Woot!");

Now you can put an anonymous function block instead of some_function

( function(tmpVar){ alert(tmpVar); } )("Woot!");

and finally the jQuery

(function($){... the $ = jQuery ...})(jQuery);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.