Change variable value js by clicking button and clicking again return to initial value

Asked

Viewed 661 times

1

I have the code js

$size = 50;

and I want to click on that button

<label for="post-1" class="read-more-trigger" onclick="$size = 500"></label>

it changes the value to 500. My only difficulty is to make the button click again and the value goes back to the initial "50". I think it is possible to do this with some if’s and E-s but I am very lay in js and I need it.

  • Quan is the HTLM of #post-1? the element has value="50"?

  • No, that’s a see-more button. What happened was that when opening the contents of this button the smooth scroll did not go to the right place since the page size was changed.

1 answer

1


honestly, I don’t see much logic in your code, but you can reach your goal using a ternary operator.

$size = 50;
<label for="post-1" class="read-more-trigger" onclick="$size = $size == 50 ? 500 : 50"></label>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.