John
John

Reputation: 177

how do I use onClick, load, show to load div

I have been trying out JS to make a button switch, show, hide text.

I have two buttons, register and login. When login is clicked, register will hide, vice versa.

Here is the link to my jsfiddle

The code here..

HTML

<button id="btn1">Login</button>
<button id="btn2">Sign Up</button>

    <div id="login">
        <h4>Login</h4>
    </div>


    <div id="register">
         <h4>Register</h4>
    </div>

JS

$("#btn2").on('click', function() {
   $("#register").show();
   $("#login").hide();
});

$("#btn1").on('click', function() {
   $("#login").show();
   $("#register").hide();
});

CSS

#register {
    display: none;
}

It seems to not be working.. Register is display as none as I want to make login show up as default.

Upvotes: 0

Views: 1615

Answers (1)

Amit Joki
Amit Joki

Reputation: 59252

You need to include jQuery first before using it.

It can be included under "Framework and extensions"

Updated Fiddle

Upvotes: 5

Related Questions