I am currently having a problem to change a global variable value in my JavaScript function. The code I am using is the following:
<script>
var open = false;
$('.header').click(function () {
$(this).find('span').text(function (_, value) {
alert(open);
if (open == false) {
$(this).addClass('fa fa-minus-circle');
open == true;
} else {
$(this).addClass('fa fa-plus-circle');
open == false;
}
/*return value == '+' ? '-' : '+' */
});
$(this).nextUntil('tr.header').slideToggle(100, function () {
});
});
</script>
I want to change the class of a span element everytime I click on it (open/close) however it only changes the class the first time and the global variable value always stay false.
I have tried to declare the global variable outside the function before the document is ready but still have the same issue. What am I doing wrong?
window.openmethod. Better use a local variable.