Something's up with my JavaScript on my local website. I decided to test by making a button:

```
<button id="test">test</button>

```

and running:

```
$('#test').click(alert("hello"));

```

The issue is that the alert happens when I reload the page and not when I press the button. I have some AJAX running on the site and some PHP and the basics (HTML, CSS, JS).

```js
$('#test').click( function() { alert("hello"); } );

function showWords(chooseDiv,str,table) {
    if (str == "") {
        document.getElementById(chooseDiv).innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById(chooseDiv).innerHTML = xmlhttp.responseText;
            }
        };
        xmlhttp.open("GET","getWords.php?filter="+str+"&table="+table,true);
        xmlhttp.send();
    }
}
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<button id="test">test</button>
```

Update
------

I have attached a snippet to show the code which on here is working but not on my site.