Ben Ben -4 years ago 61
HTML Question

Basic Javascript / jQuery Works jFiddle, but Not my Browser

I am not new to programming but I am new to Javascript and jQuery.

In my attempts to write the most basic thing, I wrote the below.

If I copy the jQuery include + my javascript and the HTML to jsFiddle, it works. When you select something on the dropdown you get the alert box.

But opening the .html file in my browser, it does not work. You can change the selection all day long and nothing happens.

I feel like this is the most basic thing but I haven't been able to figure it out. What dumb beginner mistake am I making? Javascript is client-side, so it should work I would think. I am using Chrome if it matters but same result in IE. Javascript is enabled in both.


<script src=""></script>
$('#selections').change(function() {


<select id="selections">
<option value="zero">zero</option>
<option value="one">one</option>



Answer Source

You have to put your script inside a $(document).ready() function. In JQuery, this ensures that all the events are being attached after the elements of the page has been loaded. Please see revised code below:

$(document).ready(function() {
    $('#selections').change(function() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download