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;}
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.
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.
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.
logged_in = !logged_in
Will do the trick.
Also, these two lines are the same:
if (logged_in == true)
if (logged_in)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With