I've made a custom select box that opens when a button is clicked which works fine. However, with multiple select boxes on the same page when one button is clicked all of the select boxes are opened up. Is there a way to do this without applying separate classes to each select box and multiple functions for each select box ?
Here's my HTML.
<div class="select-box-wrap">
<select class="select-box" name="mbpanel_layout_section_options[site_layout]">
<option value="1" <?php if(1 == $options['site_layout']) echo 'selected'; ?>>Left Sidebar</option>
<option value="2" <?php if(2 == $options['site_layout']) echo 'selected'; ?>>Right Sidebar</option>
<option value="3" <?php if(3 == $options['site_layout']) echo 'selected'; ?>>Three Column</option>
<option value="4" <?php if(4 == $options['site_layout']) echo 'selected'; ?>>Full Width</option>
</select>
<input type="button" class="select-click"/>
</div>
<div class="select-box-wrap">
<select class="select-box" name="mbpanel_layout_section_options[post_layout]">
<option value="1" <?php if(1 == $options['post_layout']) echo 'selected'; ?>>Left Thumbnail</option>
<option value="2" <?php if(2 == $options['post_layout']) echo 'selected'; ?>>Right Thumbnail</option>
<option value="3" <?php if(3 == $options['post_layout']) echo 'selected'; ?>>Top Thumbnail</option>
</select>
<input type="button" class="select-click"/>
</div>
and here's the jQuery.
(function($){
$(".select-click").click(function () {
var size = $('.select-box option').size();
if (size != $(".select-box").prop('size')) {
$(".select-box").prop('size', size);
$(".select-box").addClass("select-open");
} else {
$(".select-box").prop('size', 1);
$(".select-box").removeClass("select-open");
}
})
})( jQuery );
and here's a JSFiddle