In a Drupal 7 block, how to enable calling a Javascript function using behaviors 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');
$ 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".