[英]Remove last-child from jquery
I have situation where i have to delete all element(.bxwrapper) except last bxwrapper which is containing ul li from the html for this i have written jquery code which is not working properly please suggest.? 我有这样的情况,我必须删除所有元素(.bxwrapper),但最后一个bxwrapper除外,后者包含来自html的ul li,为此我编写了无法正常工作的jquery代码,请提出建议。
<div class="row" id="customBx">
<div class="bx-wrapper" style="max-width: 100%;">
<div class="bx-viewport" style="width: 100%; overflow: hidden; position: relative; height: 336px;">
<div class="bx-wrapper" style="max-width: 100%;">
<div class="bx-viewport" style="width: 100%; overflow: hidden; position: relative; height: 335px;">
<div class="bx-wrapper" style="max-width: 100%;">
<div class="bx-viewport" style="width: 100%; overflow: hidden; position: relative; height: 333px;">
<div class="bx-wrapper" style="max-width: 100%;">
<div class="bx-viewport" style="width: 100%; overflow: hidden; position: relative; height: 331px;">
<ul class="bxslider">
<li class="edSel edBxSlider editBxSlider edRemove" style="float: left; list-style: none; position: relative; width: 990px;"></li>
<li class="edSel edBxSlider editBxSlider edRemove" style="float: left; list-style: none; position: relative; width: 990px;"></li>
</ul>
</div>
<div class="bx-controls bx-has-controls-direction">
<div class="bx-controls-direction">
<a class="bx-prev" href="">Prev</a><a class="bx-next" href="">Next</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$('.bx-wrapper:not(:last-child)').remove();
</script>
You should first clone
it then remove them. 您应该首先
clone
它,然后将其删除。
var list = $('ul.bxslider').clone(true, true);
$('.bx-wrapper').remove();
Then append the cloned element to body
or some other element. 然后将克隆的元素附加到
body
或其他元素。
$('#customBx').html('<div class="bx-viewport" style="width: 100%; overflow: hidden; position: relative; height: 331px;"></div>').find('.bx-viewport').append( + list + );
You can use detach()
so try this: 您可以使用
detach()
因此请尝试以下操作:
var $lastChild = $('.bx-wrapper').last().detach();
$('#customBx').html($lastChild);
Or Simply 或简单地
$('#customBx').html($('.bx-wrapper').last());
You also try with this: 您也可以尝试以下方法:
var $lastChildren = $('ul.bxslider').parent().parent('.bx-wrapper').html(); $('#customBx').html($lastChildren);
but use into below jquery portion 但用于下面的jquery部分
$(document).ready(function(){ // Above code })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.