Rails的简单JS无法正常工作

My application.html.erb has a simple script to set time out for 3 sec and in the mean time a gif is to be displayed .But the code is not working .Also the gif is working fine if elsewise used in the document.

Can someone tell what am I doing wrong here.

   ##application.html.erb
    <script>function hideLoading() {
        $("#loading").hide();

    }

    function showLoading() {
              $("#loading").show();
           }

    function dosomething() {
        showLoading();
        setTimeout("hideLoading()", 3000);
        return false;
    }
    </script>

    </head>
    <body>
    <div id="loading">
        <img src="/assets/loading2.gif" alt="loading" />
    </div>

    <%= yield %>

    </body>
    </html>

Seems like you're defining but never calling dosomething(), so it never gets executed (unless you have not posted the code where it is called). In any case you can put a random alert('foo'); into the dosomething() function to check if it is being run.

If you're using jquery this would be an appropriate way to call dosomething() as soon as the DOM is loaded:

$(document).ready(function() {
    dosomething();
});