I keep getting error $w(...) collapse is not a function, but cant understand why

I have been following a tutorial on youtube to do collapsable menus on my site. I followed the tutorial word for word and mine doesn’t seem to be working.

The name of the box that you’d click is “box4”
And the box that is supposed to expand and collapse is “container4”

I have found that it does work when i just do
$w(“#container4”).collapse()
But when i add the numberselector in it then goes to that error and i have no clue why

I would really appreciate any help.

Thank you

Zoe

Well perhaps you should First describe what exactly you want to do?
Which function do you want to generate?

Perhaps there are even better ways of how to solve your issue?

Another question would be…
Which tutorial you were following?
I tried to read your mind but i think you are to far away​:wink::joy:

I hope you understand what i want to say.

  1. Remove to parentheses from the beginning and the end of the 5th line (the line with the expand() )

  2. Make sure you’re calling the function after the $w gets ready.

  3. Make sure the property IDs match.

Sorry I though i did explain. I want box4 when clicked to expand and collapse container4
I am a beginner at code so dont fully understand it which is why you may have found what i said vaige.

I cant share the link to the tutorial as it wont let me unfortuantely but this is its title on youtube: Menu Accordion | Collapsibles | Collapsed boxes in Wix

And I call the function in the Onready

Thank you for your reply.

You can also try this way

$w.onReady(()=>{
$w(‘Box’).onClick((event)=>{
let selectedBoxID= event.target.id
console.log(selectedBoxID);
if(selectedBoxID===“box1”) { … }
if(selectedBoxID===“box2”) { … }
if(selectedBoxID===“box3”) { … }
…and so on…
});
});