I'm using Zurb Foundation as a framework, and jQuery to show/hide a <div>
containing a Foundation based on a <select>
dropdown box. The jQuery is pretty simple:
$(document).ready(
function()
{
$('.dropdown').hide();
$('#divsp1').show();
$('select').data("previous-value", $('select').val());
$('select').change(function() {
var previousValue = $(this).data("previous-value");
$('#divsp' + previousValue).hide();
$('#divsp' + $(this).val()).show();
$(this).data("previous-value", $(this).val());
});
}
);
Simplified HTML is as follows:
<div id="divsp1" class="dropdown">
<div class="section-container auto" data-section>
<section class="active">
<p class="title" data-section-title><a href="#panel1">Section 1</a></p>
<div class="content" data-section-content>
<p>Content of section 1.</p>
</div>
</section>
<section>
<p class="title" data-section-title><a href="#panel2">Section 2</a></p>
<div class="content" data-section-content>
<p>Content of section 2.</p>
</div>
</section>
</div>
</div>
<div id="divsp2" class="dropdown">
<div class="section-container auto" data-section>
<section class="active">
<p class="title" data-section-title><a href="#panel1">Section 1</a></p>
<div class="content" data-section-content>
<p>Content of section 3.</p>
</div>
</section>
<section>
<p class="title" data-section-title><a href="#panel2">Section 2</a></p>
<div class="content" data-section-content>
<p>Content of section 4.</p>
</div>
</section>
</div>
</div>
<form autocomplete="off">
<select>
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>
Selecting anything other than the initial value causes the selected <div>
to disappear. It only reappears if the window is resized. I've also captured this behavior in a video here.
Once the window is resized, the jQuery select functions as desired. I'm seeing this issue in Firefox and Chrome, both on Windows and Mac OS X.
Is there something wrong with my jQuery that is causing this issue?
EDIT
I narrowed this down to an issue with Foundation and jQuery. I created a site with vanilla Foundation and tried to do the same thing: <div>
containing Foundation Panels that are switchable via jQuery. No luck. I'll have to find another way to achieve the same thing.