开发者

JS: querySelectorAll with respect to z-index

I would like to select all "div" elements that are children of th开发者_如何转开发e "body" and have z-index: 2 property set.

document.querySelectorAll('body > div');

How do I involve the z-index check on this querySelector?


I believe that you can't involve the "z-index" into the selector, because there's no CSS selector syntax for selecting elements based on CSS style attributes.

What you could do would be to achieve your "z-index: 2" styling by giving elements a particular class. You could then use the class in your selector ("body > div.zIndex2" or whatever).


I would probably use jQuery for a selection like that and a custom selector like:

$.expr[':'].zIndex = function(obj) {
   if ($(obj).css('z-index')==2) return true;
   else return false;
}

Then call with:

$('body div:zIndex')

but you would need jQuery for this and I haven't tested it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜