Reputation: 357
I am trying to show the first div using the following;
$('#period-to-view').change(function () {
if ($(this).val() == "Jan") {
$('div.six-month-view:eq(0)').show();
$('div.three-month-view').hide();
} else {
$('div.three-month-view').show();
$('div.six-month-view').hide();
}
if ($(this).val() == "Jul") {
$('div.six-month-view:eq(1)').show();
$('div.three-month-view').hide();
} else {
$('div.three-month-view').show();
$('div.six-month-view').hide();
}
});
The problem I am having is that :eq(0) does not work, but :eq(1) does (shows the second div). The markup is a select box that shows a div based on which month is selected (Jan or Jun).
What am I doing wrong?
Thanks
Upvotes: 0
Views: 156
Reputation: 30135
it's because if val=='Jan' it executes the else
in the second if
where you hide .six-month-view
again.
Upvotes: 2