Personally, I remove the identifier from the div (maybe apply a class if you want the selector to be a little more specific) and wrap them in the parent (let me call it target). From there, you can display only the first n child divs using a simple function. Thus, the structure:
<select id="number"> <option value="">Select...</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <div id="target"> <div style="display:none;">Section 1</div> <div style="display:none;">Section 2</div> <div style="display:none;">Section 3</div> <div style="display:none;">Section 4</div> <div style="display:none;">Section 5</div> </div>
You can use the following to bind a selection change and hide / show divs:
$(document).ready(function(){ $('#number').live('change', function() { var count = $(this).val(); $('#target div').each(function(i, n){ if(i < count) { $(n).show(); } else { $(n).hide(); } }); }); });
source share