Collapse after expand

hey, i created a dropdown-button for a container.
I would like, that you can collapse the box after you expanded it.
Maybe someone can help me :slight_smile:

This is my code:

$w . onReady ( function () {

$w ( '#readMoreButton' ). onClick ( () => { 
    $w ( '#additionalText' ). expand (); 
}); 

});

Hi @alexkemmer98

You can add an if else statement to check wether the element is visible
then add collapse expand accordingly:


$w.onReady(function () {
    $w('#readMoreButton').onClick(() => {
        if ($w('#additionalText').isVisible) {
            $w('#additionalText').collapse();
        } else {
            $w('#additionalText').expand();
        }
    });
});

Thank you ! i tried the if else before but something didnt work. :slight_smile:

@alexkemmer98

Iā€™m not an expert by any means but I tend to use this type of code:

export function readMoreButton_click(event) {
    if ($w('#additionalText').collapsed)
        $w('#additionalText').expand();
    else $w('#additionalText').collapse()
}

I tend to use the IDE for setting up the event: