A better method of doing this is to specify JS event handlers via a separate file in drupal_add_js() using Drupal.behaviors. I don't know of go-to documentation for this off of the top of my head, but do some searching and look at examples in other core modules.