简体   繁体   English

使用 Jquery 删除方法

[英]Remove method using Jquery

I have some element I want to remove but I want to keep the one that have a certain attribute我有一些要删除的元素,但我想保留具有特定属性的元素

Here is my code这是我的代码

    $(".glarry-" + activegallery + " " + ".product-gallery .thumbnails .thumbnail").not('[data-source="'+ $(this).data('source') +'"]').remove();

I also tried this我也试过这个

    $(".glarry-" + activegallery + " " + ".product-gallery .thumbnails .thumbnail:not([data-source='" + $(this).data('source') + "'])").remove();

This remove all the element, irrespective of the not这将删除所有元素,无论not

It might be because there is a space between each class name in the jquery selector.这可能是因为 jquery 选择器中每个类名之间都有一个空格。

Take a look at this post.看看这个帖子。

How can I select an element with multiple classes in jQuery? 如何在 jQuery 中选择具有多个类的元素?

For a selector that considers all those clases they must be put together对于考虑所有这些类的选择器,它们必须放在一起

$('.a.b')

you can use this kind of Selector你可以使用这种选择器

$(".example[attribute]").remove()

the selector above will get you all the atrribute with the class "example" with an attribute called "attribute" and the remove all of that selected element上面的选择器将为您提供具有名为“attribute”的属性的类“example”的所有属性,并删除所有选定的元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM