0

I am using one of the bootstrap snippet for login dropdown box in the login box there is a link for Join Us I wanted that when i click on Join Us, the content within the box should get replaced by another box that contains login credentials

I modified the following code

New here ? <a href="#"><b>Join Us</b></a>

with the code below

New here ? <a href="#" onClick="$('#login-dp').hide(); $('#signup-dp').show()"><b>Join Us</b></a>

and created another content that had id signup-dp like this

<ul id="signup-dp" class="dropdown-menu">
// signup data Inside this part
</ul>

Now when i click on the Join Us link the url of the page gets changed i.e #signup in the end of the url, but the content does not get displayed, can anyone please tell how to do so

0

6 Answers 6

1

Please check jquery included or not.

Use return false like below

<a href="#" onClick="$('#login-dp').hide(); $('#signup-dp').show(); return false;"><b>Join Us</b></a>

#signup-dp{
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" onClick="$('#login-dp').hide(); $('#signup-dp').show(); return false;"><b>Join Us</b></a>
<div id="login-dp">login-dp</div>
<div id="signup-dp">signup-dp</div>

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

Comments

0

Its very simple and you code is working for me only.

<a href="#" onClick="$('#login-dp').hide(); $('#signup-dp').show()">    
    <b>Join Us</b>
</a>
<a href="#" onClick="$('#login-dp').show(); $('#signup-dp').hide()">
    <b>Login</b>
</a>
<ul id="signup-dp" class="dropdown-menu">
    // signup data Inside this part
</ul>
<ul id="login-dp" class="dropdown-menu">
    // login data Inside this part
</ul>

Please follow this link . JSfiddle

Comments

0

Onclick jQuery is not working, So user Javascript code

New here ? <a href="#" onclick='document.getElementById("login-dp").style.display = "none";document.getElementById("signup-dp").style.display = "visible";'><b>Join Us</b></a>

Comments

0

Put the new hidden element somewhere before your existing element. unless you write your jQuery code in $(document).ready(); in a separate file, or internal.

Comments

0

Your code is correct. But please check have you included jquery file.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

This jquery should be included before the jquery code you have written.

Put following jquery code to make signup div initially hidden.

<script type="text/javascript">
    $(document).ready(function(){
        $("#signup-dp").hide();
    }); 
</script>

Comments

0

First of all, for make good programming habit you have to bind click event instead of write javascript code inside of tag onClick attribute.

<a href="#" id="btn_join_us"><b>Join Us</b></a>

In your javascript code (try to write code in other js file instead of inline code in HTML page.)

$(document).ready(function(){
    $("#btn_join_us").click(function(e){
        e.preventDefault();
        $('#login-dp').hide(); 
        $('#signup-dp').show();
        return false;
    });
});

This kind of code make some secure event binding. otherwise anyone can make change your code from inspect element and execute this.

1 Comment

thanks for the tip regarding security, will surely keep that in mind

Your Answer

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