Change js variable value when clicking button and click again to return to initial value

1

I have the js code

$size = 50;

And I want you to click this 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 when clicking the button again the value go back to the initial "50". I think it's possible to do this with some if's and else's but I'm very lay in js and I need it.

    
asked by anonymous 19.09.2016 / 21:14

1 answer

1

I honestly do not see much logic in your code, but you can get to your goal using a ternary operator.

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