0

I'm doing User Login and after doing I want the first form to be hidden and only the other field to be visible. Since I was browsing at first, it always sees it as display:block, how can I avoid this? Can anyone help with this?

So in short, how can I hide my login panel after logging in?

Thank you advance.

$(document).ready(function(){
$(".login-user").click(function () {
   $("#container").append('<div class="appendme">User Login Success</div>');
});

  $('#btn , .login, myAccount').mouseover(function(){ 
  if (jQuery('div').hasClass('appendme')){
  $('.login').css('display','none');
  $('.myAccount').css('display','block');
  }
    $('.login').show();
  }).mouseout(function(){     
    $('.login').hide();
  });    

});
.login, .myAccount{
  width:300px;
  height:auto;
  border:1px solid #CCC;
  display:none;
}
#btn{
  width:300px;
}
.appendme{
display:none
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="container">
  <button id="btn">
    My Account
  </button>
  <div class="login"> 
    Login Panel
    <button class="login-user">Login</button>
  </div>
  <div class="myAccount"> 
    <ul>
    <li>My account Edit</li>
    <li>My Wishlist</li>
    <li>My Orders</li>
    </ul>
  </div>
</div>

6
  • 1
    How do you store/identify a logged in visitor? Commented Nov 3, 2021 at 10:10
  • After logging in, I don't want the login panel to appear when navigating my account. I just want myAccount class to appear Commented Nov 3, 2021 at 10:12
  • Correct, but how do you know when someone is logged in? Commented Nov 3, 2021 at 10:17
  • When login is pressed I just create a div and a class, for example if there is such a class then the user is logged in. Commented Nov 3, 2021 at 10:22
  • Pressing login doesn't necessarily mean that the user is logged in, right? Commented Nov 3, 2021 at 10:23

1 Answer 1

1

You could use $('.login').remove();, but you should check how and when a user is logged in, and not make it dependable on a simply click event.

$(document).ready(function(){
$(".login-user").click(function () {
   $("#container").append('<div class="appendme">User Login Success</div>');
   $('.login').remove();
});

  $('#btn , .login, myAccount').mouseover(function(){ 
  if (jQuery('div').hasClass('appendme')){
  $('.login').css('display','none');
  $('.myAccount').css('display','block');
  }
    $('.login').show();
  }).mouseout(function(){     
    $('.login').hide();
  });    

});
.login, .myAccount{
  width:300px;
  height:auto;
  border:1px solid #CCC;
  display:none;
}
#btn{
  width:300px;
}
.appendme{
display:none
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="container">
  <button id="btn">
    My Account
  </button>
  <div class="login"> 
    Login Panel
    <button class="login-user">Login</button>
  </div>
  <div class="myAccount"> 
    <ul>
    <li>My account Edit</li>
    <li>My Wishlist</li>
    <li>My Orders</li>
    </ul>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.