0

I am trying to put code into a block that contains a Javascript onclick handler. Have been trying to figure out how to use drupal_add_js, but cannot figure out how to make an onclick function work. I believe I may need to use Drupal behaviors.

I have read the documentation, but it is not clear. Here is what I am trying but doesn't work. Any help would be appreciated.

drupal_add_js('jQuery(document).ready(function() { $("#trial").click(function() { alert("Handler called." ); } ); } );', 'inline');
1

1 Answer 1

1

$ isn't defined in the global scope...you either need to use a closure:

(function($) { 
  // Use $ safely here.
})(jQuery); 

or use jQuery every time

jQuery("#trial").click(...

If you check the console you should see an error in there to the effect "$ is undefined".

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.