[英]remove with jquery not in parents
How to remove all <li>
tags ( ul.gallery li )
when click on the <button>
.单击<button>
时如何删除所有<li>
标签( ul.gallery li )
。
The Button is outside the <ul>
.按钮位于<ul>
。
<div class="gallery">
<ul class="gallery-list">
<li>
<img src="sample">
</li>
<li>
<img src="sample">
</li>
<li>
<img src="sample">
</li>
</ul>
<button class="button"></button>
</div>
jQuery jQuery
jQuery('.button').on( 'click', function( e ) {
e.preventDefault();
jQuery(this).parents( '.gallery li' ).animate( { opacity: 0 }, 300,function() {
jQuery(this).remove();
});
});
Thanks in advance,提前致谢,
try like this:试试这样:
jQuery('.button').click(function(e){
e.preventDefault();
jQuery('.gallery .gallery-list li').remove();
});
or like this according to your code :或根据您的代码像这样:
jQuery('.button').on( 'click', function( e ) {
e.preventDefault();
var gallery = jQuery(this).parents( '.gallery' );
jQuery(gallery).animate( { opacity: 0 }, 300, function() {
jQuery(".gallery-list li", jQuery(gallery)).remove();
});
});
As you are looking for removing all the li
elements under the class gallery-list
.当您正在寻找删除类gallery-list
下的所有li
元素时。 You can try as below -您可以尝试如下 -
jQuery('.button').on('click', function(e) {
e.preventDefault();
jQuery('.gallery-list > li').animate({
opacity: 0
}, 300, function() {
jQuery(this).remove();
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.