1
This my code looks big and clumsy, is there any way to make it smaller? Something like "easier to write", or smaller?
Here’s my example, as you can see, I need to repeat this block 5 times, to display only one button at a time and its <div>
, One for each button I press.
Am I right? That’s how it would be?
function analysisShowPage1(){
$('#page01').removeClass('btn-warning').addClass('btn-success');
$('#page02').removeClass('btn-success').addClass('btn-warning');
$('#page03').removeClass('btn-success').addClass('btn-warning');
$('#page04').removeClass('btn-success').addClass('btn-warning');
$('#page05').removeClass('btn-success').addClass('btn-warning');
document.getElementById('analysisFullGraphContainer').style.display = 'block';
document.getElementById('analysisFullGraphContainer2').style.display = 'none';
document.getElementById('analysisFullGraphContainer3').style.display = 'none';
document.getElementById('analysisFullGraphContainer4').style.display = 'none';
document.getElementById('analysisFullGraphContainer5').style.display = 'none';
document.getElementById('copyGraph01').style.display = 'block';
document.getElementById('copyGraph02').style.display = 'none';
document.getElementById('copyGraph03').style.display = 'none';
document.getElementById('copyGraph04').style.display = 'none';
document.getElementById('copyGraph05').style.display = 'none';
}
Try to create a function that makes the command block, will save many lines of code
– gamira
I was curious about the name of that function...
analysisShowPage1
. There is also theanalysisShowPage2
andanalysisShowPage3
? That too is repetition...– Sergio