0

I'm editing the "Zen" theme in Drupal 7. And that's the problem:

 (function ($, Drupal, window, document, undefined) {        
         alert("xuy");
         $("#navigation ul.links li").hover(function() {
         alert("xuy");
    });

The first alert is working well, but there is no alert on hover. I've got this class in CSS. Even

 $("a").hover(function() { 
          alert("xuy"); 
    });

Didn't work.

AlexEfremo
  • 773
  • 1
  • 8
  • 20
  • 2
    Sounds like the code is executing before the DOM is ready. Take a look at the [`.ready()`](http://api.jquery.com/ready/) function. – Anthony Grist Jan 24 '13 at 14:38
  • nope. it's ok. `$(document).ready(function () { alert("piska"); });` still working. – AlexEfremo Jan 24 '13 at 14:46
  • Perhaps I should have been clearer before, but I was talking about needing to move the event handler binding (the `.hover()` call) in to the DOM ready, so that the elements it's trying to bind the event handler to actually exist when the code executes. – Anthony Grist Jan 24 '13 at 14:49

2 Answers2

0

Your code looks a little funky to me. Shouldn't you be using drupal behaviors in drupal 7? (yes you should).

Drupal.behaviors.mybehavior = function(context, settings){
  $('#navigation ul.links li').hover(function() {
    alert('xuy');
  });
};
2pha
  • 9,798
  • 2
  • 29
  • 43
0

you should determine $ like

(function($) {
  Drupal.behaviors.mybehavior = {
    attach: function(context, settings){
       //you code goes here
       //$ will work inside this function
    }
  };
})(jQuery);
qwertmax
  • 3,120
  • 2
  • 29
  • 42