I am working on jquery and I am trying to use slideToggle on dynamic content but I cannot make it up slide. How could make it work properly? I will provide you the http://jsfiddle.net/P3WaC/
<li class="pull-right">
<div class="text-righ padding-right">
<div class="chart">My cart (<span class="item_cart">3</span>)</div>
<button class="btn btn-warning">CHECKOUT</button>
<input type="text" class="input-large light-panel active-tab-search" placeholder="Search rewards">
</div>
<div id="cart-info" style="display: none;">
<div id="each-2" class="shopp" style="display: none;">
<div class="label">Gift voucher</div>
<div class="shopp-price">$<span class="itempr">20</span>
</div><span>Quantity: </span><span class="shopp-quantity">2</span>
<img src="../img/erop/remove.png" class="remove">
<br class="all">
</div>
<div id="each-3" class="shopp" style="display: none;">
<div class="label">Gift voucher</div>
<div class="shopp-price">$<span class="itempr">10</span>
</div><span>Quantity: </span><span class="shopp-quantity">1</span>
<img src="../img/erop/remove.png" class="remove">
<br class="all">
</div>
</div>
$('.pull-right').on('click',function(){
alert( $('#cart-info').text());
$('#cart-info').slideToggle('slow');
});
The dynamic content is under cart-info. I want to display the items and hide them accordingly.
Remove display:none;
off the child div's of #cart-info
, or else they won't show!
Just show the .shopp
elements before sliding the parent:
$('.pull-right').on('click',function(){
alert( $('#cart-info').text());
$('#cart-info').find('.shopp').show(); //added line
$('#cart-info').slideToggle('slow');
});
Living demo: http://jsfiddle.net/P3WaC/2/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.