While working on an answer to this question I created this jsfiddle. For some reason it isn't working, and when I used firebug's error consol it was returning that ".show" is not a function. This leads me to believe that jsfiddle is incorrectly loading jQuery. Are there any known issues between JSFiddle and jQuery? Is my code simply incorrect (BTW when I change .show("slow")
to .style.display = "inherit"
it works fine which is why I think it has to be a problem with jQuery...)
A working JSFiddle would be greatly appreciated.
A couple of issues:
}
.(Note the wrapping). jQuery methods don't magically extend default elements, the object must be wrapped first.
Note now that this version works.
EDIT:
Alternatively, you could use the second parameter of jQuery's construct (scope) and shorten this code:
EDITv2
Juan brought up a good point, you should also separate javascript with markup. By this I mean avoid using the on* attributes of the elements, and keep the bindings within the external .js file or
<script>
tags. e.g.I am really not a fan of obtrusive javascript :p
You should get used to never ever using the inline event handlers, and instead use jQuery's event binding.
Better solution:
http://jsfiddle.net/ttweX/2/
Also the one Tomh linked does some weird infinite blinking obnoxiousness.
I modified it to this:
See: http://jsfiddle.net/ttweX/