简体   繁体   English

如何在jquery中定位不透明度的属性?

[英]How do I target attribute of opacity in jquery?

I know about the attributeContains selector, but how does it apply to style attributes? 我知道attributeContains选择器,但它如何应用于样式属性?

I want to find all <a> tags that have their opacity set to 0. 我想找到所有<a>标签,其不透明度设置为0。

I tried this : 我试过这个:

$("a[style*='opacity: 0']")

But it returns nothing. 但它什么也没有回报。

The :visible selector will not work because it doesn't give consideration to opacity. :visible选择器不起作用,因为它没有考虑不透明度。

To target just those with a 0 opacity, you could use a .filter() to check the .css() value of the opacity: 要仅针对具有0不透明度的那些,可以使用.filter()来检查不透明度的.css()值:

$("a").filter( function() {
    return $(this).css('opacity') === '0';
});

You could create your own selector if you'd like: 如果您愿意,可以创建自己的选择器:

$.extend($.expr[':'], {
    opacity: function(elem, i, attr){
      return( $(elem).css("opacity") === attr[3] + '' );
    }
});

var $invisible = $("a:opacity(0)");

or 要么

$.extend($.expr[':'], {
    transparent: function(elem, i, attr){
      return( $(elem).css("opacity") === "0" );
    }
});

var $invisible = $("a:transparent");

如果您想知道元素是否可见,请使用:

$('a:not(:visible)');

$('a:not(:visible)')

Your code won't work as it only works when the opacity is applied on the element's style attribute - what about CSS styles??? 你的代码不起作用,因为它只在不透明度应用于元素的样式属性时才有效 - 那样的CSS样式??? they won't apply. 他们不会申请。 jQuery provides the :visible and :not selectors, so you can combine them. jQuery提供:visible:not selectors,因此您可以将它们组合在一起。 http://api.jquery.com/category/selectors/ http://api.jquery.com/category/selectors/

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

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