That snippet ‘works’ for me.
Is the script being printed at the bottom of the page? More specifically, does your theme call wp_footer
. All themes should, but not all themes do call wp_footer
which breaks plugins which rely on it.
For the record – you should not print scripts directly to the page. WordPress has a great API for handling JavaScript enqueing and dependency handling. See this codex page.
You may also find this question helpful too.