I would like to select all "div" elements that are children of the "body" and have z-index: 2 property set.
document.querySelectorAll('body > div');
How do I involve the z-index check on this querySelector?
I would like to select all "div" elements that are children of the "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