Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to toggle a variable from true to false

I have this setup: http://jsfiddle.net/patrioticcow/yJPGa/5/

I can't figure out how how to toggle in between a true or false variable. Here is the code:

<div class="test" id="id_test">Some Content...</div>
<div style="display: none" id="id_test">Some Other Content...</div>
<div>
  <button id="disable">Save</button>
  <button id="enable">Edit</button>
</div>

js

var logged_in = false;

$("#disable").click(function() {
  logged_in == true;
  alert (logged_in);
});

$("#enable").click(function() {
  logged_in == false;
  alert (logged_in);
});

if (logged_in == true) {
  $("#id_test").find(".test").removeClass(".test").addClass(".test_hidde");
}

css

.test{color: red;font-size: 16px;}
.test_hidde{color: #000;font-size: 26px;}
like image 227
Patrioticcow Avatar asked Mar 29 '11 19:03

Patrioticcow


People also ask

How do you change a variable from true to false in Python?

We can evaluate values and variables using the Python bool() function. This method is used to return or convert a value to a Boolean value i.e., True or False, using the standard truth testing procedure.

How do you change a boolean to a false variable?

To initialize or assign a true or false value to a Boolean variable, we use the keywords true and false. Boolean values are not actually stored in Boolean variables as the words “true” or “false”. Instead, they are stored as integers: true becomes the integer 1, and false becomes the integer 0.

How do you flip a Boolean variable in Java?

Toggling a Primitive boolean Variable Therefore, every time we perform the NOT operator on a boolean variable, its value will be inverted. Alternatively, the XOR operator (^) can also invert a boolean.


1 Answers

logged_in = !logged_in

Will do the trick.

Also, these two lines are the same:

if (logged_in == true)
if (logged_in)
like image 194
Dean Barnes Avatar answered Oct 29 '22 22:10

Dean Barnes