I am trying to load a javascript file for my module. The javascript code should execute and dynamically apply some CSS styling.
However, my jQuery is not having any effect. Plain vanilla javascript code works but not my jQuery code.
I am loading my javascript with the following code:
drupal_add_js(drupal_get_path('module', 'my_module') .'/js/mycode.js', 'file');
I'm applying this code outside of any function but loaded it in hook_node_view
when the $view_mode
is full.
And the following is my javascript:
(function ($) {
alert('RESPONDING!');
$('#page').css('background', 'red')
alert('RESPONDING-2!');
jQuery('body').click(
function () {
alert('clicked!');
}
);
})(jQuery);
Nothing $/jQuery tagged works but both alert statements work.
I would appreciate any help with this.