Stop WordPress processing Javascript as text

The post editor is really not meant for inserting functional code like JavaScript into the page.

Anything you put through the post editor will get run through wpautop() before output, which is what adds the paragraph tags — even if you enter it via the Text mode. I’d suggest outputting your JavaScript via a hook on the page instead of via the post editor.

Something like this:

/**
 * Output JS to the page head.
 */
function output_head_js() {
    ?>
    <script type=“text/javascript”>
        $( ‘#gosearch’ ).click( function() {
        …
    });
    </script>
    <?php
}
add_action( 'wp_head', 'output_head_js' );