Hi, I’m trying to assign a $w object to a variable and then check if the variable is the same as the $w object. The result is always “false” - but why? Hpw can I assign the variable correctly so the result becomes “true”
Hi, thanks for reaching out. Console result is “false”.
I need to declare the object as variable for a kind of menu. several buttons collapse/expand containers when pressed. I need to remember the last container expanded, to collapse it when a button is pressed again.
Here is the whole code:
var mobileMenuActiveContainer;
var mobileMenuActiveTitle;
export function button1_click(event) {
let navPoint = $w("#button1Container");
let thisItem = $w("#button1");
if (navPoint.collapsed === true) {
navPoint.expand();
//check if the last expanded container is not the same which is opened now.
if (mobileMenuActiveContainer !== undefined && mobileMenuActiveContainer !== navPoint) {
mobileMenuActiveContainer.collapse();
mobileMenuActiveTitle.style.backgroundColor = colorWhite;
mobileMenuActiveTitle.style.color = colorAragoBlue;
}
//assign variables to remember which container was last opened.
mobileMenuActiveContainer = navPoint;
mobileMenuActiveTitle = thisItem;
thisItem.style.backgroundColor = colorLightBlue;
thisItem.style.color = colorLearningBlue;
}
else {
navPoint.collapse();
thisItem.style.backgroundColor = colorWhite;
thisItem.style.color = colorAragoBlue;
}
}
export function button2_click(event) {
let navPoint = $w("#button2Container");
let thisItem = $w("#button2");
if (navPoint.collapsed === true) {
navPoint.expand();
//check if the last expanded container is not the same which is opened now.
if (mobileMenuActiveContainer !== undefined && mobileMenuActiveContainer !== navPoint) {
mobileMenuActiveContainer.collapse();
mobileMenuActiveTitle.style.backgroundColor = colorWhite;
mobileMenuActiveTitle.style.color = colorAragoBlue;
}
//assign variables to remember which container was last opened.
mobileMenuActiveContainer = navPoint;
mobileMenuActiveTitle = thisItem;
thisItem.style.backgroundColor = colorLightBlue;
thisItem.style.color = colorLearningBlue;
}
else {
navPoint.collapse();
thisItem.style.backgroundColor = colorWhite;
thisItem.style.color = colorAragoBlue;
}
}
//I have 5 more of tose buttons and functions
The problem is, that…
if (mobileMenuActiveContainer !== undefined && mobileMenuActiveContainer !== navPoint) {
…always results true, even if mobileMenuActiveContainer and navPoint are the same!