It is easier to attach JS to form element in D7.  
```php
$element['#attached']['js'][] = drupal_get_path('module', 'media') . '/js/media.js';
```