Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

jQuery code works but want to make sure this is a good way of hiding/displaying

As part of my code clean up of what the ex-developer has, I want to make sure this is good to leave as is or if there's a better (I'm looking for mainatable code) way of doing this

1. There are divs with classes and these divs are hidden/displayed based on what the user selects from a dropdown. I can leave it as is, if there isn't a cleaner way

User generated image
2. A change function is called and the divs are hidden and displayed like this

$(document).on('change', '#scheduleArea .schedule select.typeSelector', function () {

   .....

var scheduleDiv = $(this).parents('.schedule');
...
var classToDisplay = '';
		switch (value) {
			case 'O':
				classToDisplay = 'scheduleOnce';
				break;
			case 'D':
				classToDisplay = 'scheduleDaily';
				break;
			case 'W':
				classToDisplay = 'scheduleWeekly';
				break;
			case 'M':
				classToDisplay = 'scheduleMonthly';
				break;
			default:
				break;
		}
		if (classToDisplay != '') {
			$('.' + classToDisplay, scheduleDiv).removeClass('hidden');
			if (value != 'O') $('.endDate', scheduleDiv).removeClass('hidden'); // Don't display end date for Once runs
			$('.export', scheduleDiv).removeClass('hidden');
			$('.emailAddresses', scheduleDiv).removeClass('hidden');
			$('.timeZone', scheduleDiv).removeClass('hidden');
		}

Open in new window

SOLUTION
Avatar of Dmitriy Sky
Dmitriy Sky
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Camillia

ASKER

yeah, they do use IE 11.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, Chris. Let me take a look
thanks, as always.