Search code examples
jquerydrupal-7

Drupal 7 jQuery issue


I know Drupal 7 jQuery code needs to be wrapped in a way which allows other libraries that use the $ notation to work. I have accounted for that as my code below shows:

(function($){
    alert('working');
    console.log('working');
    jQuery('#logo').hide();
    $('table#nodesequence_nodes').click(
        function(){
            console.log('still working');
        }
    );
})(jQuery);

The strange thing is, my calls to $ and jQuery don't work. The code to hide #logo for instance does not work neighter does the table click code. They don't generate errors ... they are simply completely unresponsive.

The alert and console.log code samples DO work.

My jQuery and my JavaScript file are both successfully loaded according to firebug.


Solution

  • I think it might be because not all the HTML has loaded yet. You should try using the Drupal prescribed way of running scripts. Go to this page and scroll down to the section titled "Behaviors": drupal.org/node/756722