Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find element with specified z-index

How to find HTML element(-s) with z-index = 10 for example?

like image 204
Sergey Metlov Avatar asked Apr 13 '12 15:04

Sergey Metlov


People also ask

How do you specify Z index?

If you want to create a custom stacking order, you can use the z-index property on a positioned element. The z-index property can be specified with an integer value (positive, zero, or negative), which represents the position of the element along the z-axis.

How do you solve Z Index problems?

To sum up, most issues with z-index can be solved by following these two guidelines: Check that the elements have their position set and z-index numbers in the correct order. Make sure that you don't have parent elements limiting the z-index level of their children.

Does Z Index work with position relative?

Note: Z index only works on positioned elements ( position:absolute , position:relative , or position:fixed ).

What is Z Index 9999?

In CSS code bases, you'll often see z-index values of 999, 9999 or 99999. This is a perhaps lazy way to ensure that the element is always on top. It can lead to problems down the road when multiple elements need to be on top.


3 Answers

One possible [jQuery] solution:

$(".elementsToSearch").each(function()
{
    if($(this).css('z-index') == 10)
    {
        //then it's a match
    }
});

Just loops through elements searching for a match to the css rule.

like image 110
orourkek Avatar answered Oct 13 '22 15:10

orourkek


You can get all elements and filter them by css property:

$('*').each(function(){
    if($(this).css('z-index') == 10) {
        //$(this) - is element what you need
    }
});
like image 25
antyrat Avatar answered Oct 13 '22 16:10

antyrat


You have to iterate over all elements and check their z-index:

$('*').filter(function() {
    return $(this).css('z-index') == 10;
}).each(function() {
    // do something with them   
});
like image 30
ThiefMaster Avatar answered Oct 13 '22 15:10

ThiefMaster