I’ve been trying to create a little box at the bottom of my webpage which will expand / pop-up when scrolled over and then close again when the mouse moves away.
I f
You are running this code immediately, rather than waiting for the DOM to be ready. This means that the element #box
may not exist yet.
jsFiddle automates this process to make your code cleaner. You need to do it yourself when you put the code into your own website. It is very easy: you just need to put your code into a callback to the ready event on the document:
$(document).ready(function() {
// put your Javascript here
});
or, a shortcut version:
$(function(){
// put your Javascript here
});
These are semantically and functionally equivalent.