views:

228

answers:

2

Hi.

I need a small function for jQuery that would close multiple DIV elements, but I'm having trouble with JS syntax.

I got this far:

function closePanels{
$("#servicesPanel").hide("fast");
$("#portfolioPanel").hide("fast");
$("#contactPanel").hide("fast");
$("#aboutPanel").hide("fast");
};

Sounds logical to me: That way I want to call the function from various points in the DOM. Where do I get it wrong? How do I write this function so it'll work?

Thank you.

+6  A: 

Ohhh, So close!

this:

function closePanels{

needs to be:

function closePanels () {

Note the addition of brackets (cause it's a function).

Noon Silk
Thanks. BTW: how do I call it from another function?
konzepz
Same way as any language - `closePanels()`
Daniel Roseman
+4  A: 

In addition to the missing () why dont you give give each panel div a class of say panel. This will allow you to code less hide methods by saying just

$('div.panel').hide();

Of course you may have more panels and you dont wish to hide them all but i cannot tell without the markup. its merely an option.

redsquare
My project has few ID elements ("#portfolioPanel" for example, is one of them). I need to open them individually and close them all at once, form various points of the website.That's why (I think) I need this function, so I can call it form where ever, when ever, to just reset things for the user.
konzepz