Help - Hide button when a user is logged in

I want to make a button invisible when a user is logged in.
In the page where I want it to happen, I added the code below and it doesn’t work.
Any suggestions? TNX!

import wixUsers from ‘wix-users’;

$w.onReady( function () {
if (wixUsers.currentUser.loggedIn) {
$w(‘#button1’).isVisible = false ;
}
});

Why not just use the show and hide option instead?

Have a look at this page too:
https://support.wix.com/en/article/wix-code-tutorial-building-your-own-members-area

https://www.wix.com/code/reference/$w.HiddenMixin.html#isVisible
https://www.wix.com/code/home/example/Hide-and-Show-Elements


import wixUsers from 'wix-users';
 
$w.onReady( () => { 
if (wixUsers.currentUser.loggedIn) {
$w('#button1').hide();
}
else {
$w('#button1').show();
}
});  

Awesome! didn’t notice that it’s possible.
THANK YOU!

Hi Guys.
So i want to hide my text on desktop whether a user is logged in or not, i want my image to show on desktop if the user isn’t logged in but to hide if they are.
This all works.
But i want the text and image to show on mobile if they are not logged in and both the text and image to hide if they are.
This second part doesn’t work.
Can anybody help? :slight_smile:
Im new to this so its probably all wrong and a mess

import wixWindow from ‘wix-window’ ;
import wixUsers from ‘wix-users’ ;

$w.onReady( function () {

if (wixUsers.currentUser.loggedIn) {
$w( ‘#vectorImage4’ ).hide();
}
else {
$w( ‘#vectorImage4’ ).show();
}

{ if (wixWindow.formFactor === “Desktop” )

$w( “#text11” ).hide();

else {

$w( “#text11” ).show();

$w( “#vectorImage4” ).show();

}}});

Hi GOS, hope you are doing good.

I have attached your code to my Dev Tool but, once I logged in the site keeps showing me the button, if I reload the page then the button hides but it is supposed to load as soon as I log in right?

Thanks for your help