Need help pls (Hide/Show text with a button)

Hi everybody, I am a novice in code …

I make a hidden text that appears with clicking a button (button name : “+”).
This I have achieved ! :blush:

$w . onReady ( function () {
$w ( ‘#button’ ). onClick ( () => {
$w ( #hiddentext ). expand ();

Now I wish the button to change its name (to “-”) and when you click on it, the text disappears (initial status), and the button becomes “+” again.

it would be really great if someone could give me the rest of the code to reach my goal :blush:

Thanks a lot

How about this…

$w.onReady(function () {
  $w("#button").onClick(() => {
    if ($w("#hiddentext").collapsed) {
      $w("#button").label = "-";
    } else {
      $w("#button").label = "+";

Note: to be consistent with variable naming conventions in JavaScript, you might want to rename the element ‘hiddentext’ to ‘hiddenText’, using camelcase capitalization.

Here’s the result – before click and after click:

1 Like

@Jim Feuerstein,
A thousand thanks, it works perfectly with your help :blush:
I thank you sincerely and greetings from Switzerland.

NB. And with your note, I renamed elements using camelcase capitalization.

1 Like

Thanks for the update!