It would be better to add the JavaScript at 'wp_footer' action instead of inline.