I am trying to write a menu whose subitems vanish when the page is loaded.
If you need full HTML, I will copy it, however it just consists of a bunch of DIVs, the items under the headers have a class of subitems.
I have managed to do what I need via:
$(document).ready(
$(".subitems").hide()
);
However, in Chrome, despite it working fine, I get the following error in the console:

(Using picture as I can’t copy the formatting well)
When I remove the above code, the error goes. I guess I have done something wrong, but I can’t see it and so far it works in every browser I have tested.
Any suggestions on either:
- Have I done something wrong?
- Is there a better way to achieve what I want?
You’re missing the anonymous function(
function() { }) wrapper, like this:It’s trying to do
$(".subitems").hide().call()under the covers when it executes thereadyhandlers…but this isn’t a function. Instead, it’s executing immediately (not ondocument.ready) and throwing an error whendocument.readytries to run the result of.hide().Just to note, there’s a shorter form of the above as well: