Problem in if statement...

Hi,

Could you PLEASE help me out with the following code? It’s in the same event.It should show the $w(" #loggedbox “) if $w(” #log “) text is not empty. If it’s empty then it should show $w(” #notloggedbox ").But when it’s not empty it shows both but it only outputs the console.log(“logged: " + $w(” #log ").text).That is so weird, please can you help me?

And BTW - the $w(" #log ").text = local.getItem(…)

if ($w("#log").text !== "") {
         console.log("logged: " + $w("#log").text);
         $w("#notloggedbox").hide();
         $w("#loggedbox").show();
         $w("#loadingacc").hide();
         
         // ...
         
         } else if ($w("#log").text === "") {
                      console.log("not logged: " + $w("#log").text);
                      $w("#notloggedbox").show();
                      $w("#loggedbox").hide();
                      $w("#loadingacc").hide();
         } 
if ($w('#log').text ){//or text.length if it's always a string
      console.log("logged: " + $w("#log").text); 
      $w("#notloggedbox").hide();
      $w("#loggedbox").show(); 
      $w("#loadingacc").hide(); 
else{
       console.log("not logged: " + $w("#log").text); 
       $w("#notloggedbox").show(); 
       $w("#loggedbox").hide();
       $w("#loadingacc").hide(); 
  }

You can read about if/else if /else here JavaScript if else else if

Hey. Try this in your if statement instead.

if (!$w('#text1').text) {

Tried all suggestions but it still shows both $w(" #loggedbox “) and $w(” #lnotoggedbox ") but doesn’t executes both console.log

Actually it’s working now. It appears to be that it works sometimes and other times it doesn’t.

Hey everyone, I looked in the Wix Code API reference and took a look at the $w.onReady event and read the note and went to another page (Velo: About the Page Rendering Process | Help Center | Wix.com). There are scenarios where the event can cause problems, including my case wich uses Wix Storage.

So the solution is adding the following to the code:

 if (wixWindow.rendering.env === "browser") { 

I read the section about that on the page, and now I got it. You can read it for yourself if you’re wondering why that solves the problem.