There’s a number of ways. A quick and dirty way would be to reference an external jQuery library with a <script>
block in your theme’s header.php template, then place your script in another <script>
block. That’s not really the “right” way.
The right way seems quite convoluted for a one line script, but it’s good to be acquainted with it anyway. First you need a plugin or child theme to contain your code. This protects it during updates. The quick and dirty method mentioned earlier would be lost when you update your theme.
Next put your script in an external .js file. Then on your plugin code page or child theme functions.php, enqueue your script file using wp_enqueue_script(). Be sure to specify ‘jquery’ as your script’s dependency. It must be in an array even if it’s the only dependency. Also note the section on noConflict wrappers and the first item in the Notes section.
It’s not all as bad as it sounds, though it’s still a bit much for a one liner. It is however, The Way?.