jquery - Hide/show all DIV but the one picked -
see have html code:
<form method="post" id="product_create" action=""> <ul> <li id="tab1"><a href="#">step 1</a></li> <li id="tab2"><a href="#">step 2</a></li> <li id="tab3"><a href="#">step 3</a></li> <li id="tab4"><a href="#">step 4</a></li> </ul> <div id="categories-picker"></div> <div style="display:none" id="product-select"></div> <div style="display:none" id="product-details"></div> <div style="display:none" id="product-stock"></div> </form>
i need show/hide div
others picked one. in case if click in li#tab1
div#categories-picker
should show , others should hide no matter meaning example if in div#product-stock
. same behavior should go rest. made code:
$("#product_create").on("click", "tab1, tab2, tab3, tab4", function() { $('#product_create').not($(this)).hide(); });
any advice on this? maybe better way don't find it
build kind of relation between <li>
s , <div>
s need displayed on clicking <li>
s. below i've added data
attribute, display
each <li>
indicate <div>
displayed on clicking each.
<form method="post" id="product_create" action=""> <ul> <li id="tab1" data-display="categories-picker"><a href="#">step 1</a></li> <li id="tab2" data-display="product-select"><a href="#">step 2</a></li> <li id="tab3" data-display="product-details"><a href="#">step 3</a></li> <li id="tab4" data-display="product-stock"><a href="#">step 4</a></li> </ul> <div id="categories-picker"></div> <div style="display:none" id="product-select"></div> <div style="display:none" id="product-details"></div> <div style="display:none" id="product-stock"></div> </form>
and use relation show appropriate <div>
$("#product_create").on("click", "#tab1, #tab2, #tab3, #tab4", function() { $('#'+$(this).data('display')).show().siblings('div').hide(); return false; });
update:
changing div if isn't empty
$("#product_create").on("click", "#tab1, #tab2, #tab3, #tab4", function() { var div = $('#'+$(this).data('display')); if($.trim(div.html()) !== '') { $('#'+$(this).data('display')).show().siblings('div').hide(); } return false; });
Comments
Post a Comment