javascript - jQuery Two Tabs -
i have 2 tabs: login & register. it's simple, hide login section when register tab clicked , vice versa. when click on register tab, login section hidden , it's working, when try click again on login tab, messed up.
here code:
jsfiddle.net/gdc5ryqj/
i created fork of fiddle here:
it appears using bootstrap, recommend using bootstrap tabs if possible , applying styles, if that's not option, here example (link above jsfiddle).
html: changed element tab uses determine active state <div>, rather <p>, , put class 'active' on login tab make 1 shown default.
i added couple of lines css @ end:
/*** additional styles (ryantdecker) ***/ #tab-login, #tab-register {display:none;} #tab-login.tab-active, #tab-register.tab-active {display:block;} .login-reg-tab {} .login-reg-tab.active p { color: #e76e5d; border-bottom: 3px solid;} lastly, jquery removing active , tab-active classes tab , panel areas respectively, , adding them appropriate ones based on element clicked, css takes care of hiding , showing
$(document).ready(function(){ $('.login-button').click(function(){ $('.login-reg-tab').removeclass('active'); $(this).addclass('active'); $('.login-reg-input-holder').removeclass('tab-active'); $('#tab-login').addclass('tab-active'); }); $('.register-button').click(function(){ $('.login-reg-tab').removeclass('active'); $(this).addclass('active'); $('.login-reg-input-holder').removeclass('tab-active'); $('#tab-register').addclass('tab-active'); }); }); (there ways make simpler, not without reworking markup , classes quite bit, , see have crazy big css file need refactored.)
Comments
Post a Comment