Q:

jQuery hide div after hash link is clicked

HTML:
<div id="text" class="text">
   Hello World! <a href="#hide">CLOSE</a>
</div>

Script:
$(function() {
    if ( document.location.href.indexOf('#hide') > -1 ) {
      $('#text').fadeOut('slow');
    }
});

That does not hide "text" div after click. It works if I go directly "www.mysite.com/#hide" tho.

A:

You want to select the link with the href="#hide"? Use the attribute-equals selector: 
$(function() {
    $("a[href='#hide']").click(function() {  $('#text').fadeOut('slow');});
});

The link itself would be treated as an local anchor (means on the same page). This won't cause the browser to reload the page and therefore your script won't be executed. In modern browsers you could capture these changes via the hasChange event.

