2

I made a custom module and I added the following code inside the php tag and also in my hook_menu function

drupal_add_js('jQuery(document).ready(function () { alert("Hello!"); });', 'inline');

I can't figure out why it's not firing.

When I look at the 'view source' of the page I do see this:

<script type="text/javascript"> <!--//--><![CDATA[//><!-- jQuery(document).ready(function () { alert("Hello!"); }); //--><!]]> </script>

2
  • You just added it right inside of the <?php tag? Best practice would be to wrap it in a mymodule_init(){ ... } function.
    – Chance G
    Jun 13, 2012 at 22:07
  • Ok, just added it to my mymodule_init()....But still nothing..:(
    – airnet
    Jun 14, 2012 at 5:34

1 Answer 1

2

Go through this document http://drupal.org/node/171213 It shows how to use Jquery. The syntax for jquery ready function is:

jquery(document).ready(function($) {
// Code that uses jQuery's $ can follow here.
});
5
  • :(, i added the $ to the function argument...still nothing
    – airnet
    Jun 14, 2012 at 22:16
  • damn.......all this time, I had to clear cache ...F******
    – airnet
    Jun 15, 2012 at 3:13
  • that's quite frustrating when you are learning
    – airnet
    Jun 15, 2012 at 3:14
  • it's quite annoying to always having to clear cache :(
    – airnet
    Jun 15, 2012 at 3:20
  • 1
    You need to clear cache every time when you make changes :)
    – Dharmender
    Jun 15, 2012 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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