Collapsible content
What am I doing wrong in here?
https://codepen.io/myntsu/pen/gOKYOep
I'm trying to make a collapsible content.
Also, I want to make it collapse again when out of users' vision, but I can't grasp my head around on how to do it.
9 Replies
Basically the content deploys (or should) on triggering the arrow downwards.
getElementsByClassName
returns an array, so if you want to use that for collapsible
, you have to use var collapsible = document.getElementsByClassName("collapsible")[0];
with the [0]
at the end, or handle the fact that it's an array whenever you use it
var content = collapsible[0];
would work too
I'd also recommend not using var
anymore, use const
unless you know you need to change the variable, then use let
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
the "collapse when out of users vision" will be strange. It will make the page jump as soon as it collapses
for the toggle collapse part itself
personally i like the inline onclick event. That is reusable (just change the parameter to select the target). Something like this
I generally avoid the onclick attribute in HTML, it's usually better to do that all in your javascript... but this is nice and compact
i think for a small project it is totally fine
yeah, agreed
without the onclick, but still easy manageable and reusable. without having to dive in the js
Noted both things.
I was thinking of, whenever you click a link, it collapses back.