简体   繁体   中英

Button's onclick function is not working

I don't know why this function is not working.

HTML:

<button id="welcomehomebtnlogin" type="button" onclick="loginformfunction()">Login</button>

JavaScript:

function loginformfunction()
{
    document.getElementById("welcomehomebtndiv").style.display = "none";
    document.getElementById("loginform").style.display = "block";
}

What I want to do is: if the user clicks on the "Login" button, one form will disappear with display = "none" . The button is part of this form, and it will also disappear. Then a second form will be shown.

It's not working; any ideas why?

Your code look fine, check the basic example bellow.

Hope this helps.


 function loginformfunction() { document.getElementById("welcomehomebtndiv").style.display = "none"; document.getElementById("loginform").style.display = "block"; } document.getElementById("welcomehomebtnlogin").addEventListener('click', loginformfunction, false); 
 #loginform{ display: none; } 
 <div id='welcomehomebtndiv'> Welcome HOME div <button id="welcomehomebtnlogin" type="button">Login</button> </div> <div id='loginform'> Login div </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM