There has to be a simpler way to handle this situation. Currently, I have a modal with 4 hidden forms, one of which is active based on the "active" class. I want to show each form when different buttons like sign-up, forgot password, or sign-in are clicked.
I thought about creating:
function modalSwitch() {
var btnModal = [$('.btn-one'), $('.btn-two'), $('.btn-three'), $('.btn-four')];
var formModal = [$('.form-one'), $('.form-two'), $('.form-three'), $('.form-four')];
btnModal.click(function(){
if ( btnModal[].hasClass('active') && btnModal[].attr('class') === formModal[].data('id')) {
formModal.addClass('active');
}
});
}
modalSwitch();
instead of using separate click events for each button and form:
function modalSwitch() {
var btnOne = $('.btn-one');
var btnTwo = $('.btn-two');
var btnThree = $('.btn-three');
var btnFour = $('.btn-four');
var modalOne = $('.modal-one');
var modalTwo = $('.modal-two');
var modalThree = $('.modal-three');
var modalFour = $('.modal-four');
btnOne.click(function(){
modalOne.addClass('show');
modalTwo.removeClass('show');
modalThree.removeClass('show');
modalFour.removeClass('show');
});
}
modalSwitch();
I'm feeling a bit overwhelmed right now, any assistance would be greatly appreciated