With my fiddle, I made it to highlight on one of main menu buttons when loaded and show() and hide() corresponding button set in the bottom.
What I think is wrong but can't figure out myself is something to do $this variable's reference scope in my switch statement. In my case, $this points to the clicked button value which I presume is the name of the class but in my switch statement, I am not sure whether I can reference the id names from $this. I guess my question is what value does $this hold in my scenario?
It would be nice to see a working example, possibly with less code as I can see many duplicates where it could be simplified.
$('.menu').click(function () {
if ($(this) != $('.highlight')) {
$(this).addClass('highlight')
.siblings('.menu')
.removeClass('highlight');
}
switch ($this) {
case '#dateMenu':
$('.date-chart').show();
$('.jc-chart').hide();
$('.jp-chart').hide();
$('.ws-chart').hide();
break;
case '#jcMenu':
$('.date-chart').hide();
$('.jc-chart').show();
$('.jp-chart').hide();
$('.ws-chart').hide();
break;
case '#jpMenu':
$('.date-chart').hide();
$('.jc-chart').hide();
$('.jp-chart').show();
$('.ws-chart').hide();
break;
case '#wsMenu':
$('.date-chart').hide();
$('.jc-chart').hide();
$('.jp-chart').hide();
$('.ws-chart').show();
break;
}
});
switch (this.id) ... case ("wsMenu")- but you likely just need to hide the siblings and show $this once you set $this=$(this) - and you need $(this).hasClass('.highlight')debugger;in your code and open up your console in firefox or chrome.console.log(this)$this?? i guess that should be$(this)which again makes no sense.. :)