Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hi I have two JavaScript elements for logging into and create an account. They both overlap each-other when the div id is clicked and I need them to hide when the other id is clicked and vice versa.

<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery('#sign-in').live('click', function(event) {        
         jQuery('#login-content').toggle();
    });
});
jQuery(document).ready(function(){
    jQuery('#create-account').live('click', function(event) {        
         jQuery('#create-content').toggle();
    });
});
</script>
share|improve this question

closed as off topic by s_ha_dum, brasofilo, toscho Apr 7 '13 at 5:49

Questions on WordPress Development Stack Exchange are expected to relate to WordPress within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 0 down vote accepted

Since you want them to alternate the easiest would be to use show() and hide() rather than toggle(), since you don't actually want to toggle the visibility if the login is clicked more than once, you want it to always show the #login and hide the #create. Also note that the live() function has been deprecated in favor of on(). See this example:

jQuery(document).ready(function(){
    jQuery('#sign-in').on('click', function(event) {        
         jQuery('#login-content').show();
         jQuery('#create-content').hide();
    });
    jQuery('#create-account').on('click', function(event) { 
         jQuery('#create-content').show();       
         jQuery('#login-content').hide();  
    });
});
share|improve this answer
    
thanks for the answer. I want to add some more code so when i click outside the div it hides. –  wordpress_designer Apr 7 '13 at 4:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.