2012-04-13 27 views
10

¿Cómo encontrar el elemento HTML (-s) con z-index = 10 por ejemplo?Buscar elemento con índice Z especificado

+0

posible duplicado de [jQuery: ¿Se puede seleccionar por regla CSS, sin clase?] (Http://stackoverflow.com/questions/43926/jquery-can-you- select-by-css-rule-not-class) –

+0

también: [jQuery find by inline css attribute] (http://stackoverflow.com/questions/1180067/jquery-find-by-inline-css-attribute) – aruseni

+1

Don 't. Si usa este enfoque, probablemente esté haciendo algo mal. Usa identificadores o clases en su lugar. – Blazemonger

Respuesta

17

Tienes que iterar sobre todos los elementos y comprobar su z-index:

$('*').filter(function() { 
    return $(this).css('z-index') == 10; 
}).each(function() { 
    // do something with them 
}); 
1

Una posible solución [jQuery]:

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

Sólo bucles a través de elementos en busca de una coincidencia con el css regla.

1

Usted puede obtener todos los elementos y filtrarlos por propiedad CSS:

$('*').each(function(){ 
    if($(this).css('z-index') == 10) { 
     //$(this) - is element what you need 
    } 
}); 
0

En mis pruebas en Chrome 43, encontré @ThiefMaster's post a ser útil, pero no al 100%. El valor de z-index que se tiraba era una cadena.

También hice esto iterar sobre elementos visibles y manejar auto.

Aquí está mi actualización:

var topZ = $('.thing-in-front').css('z-index') 
if (topZ != 'auto') { 
    topZ = parseInt(topZ); 
    $('*:visible').filter(function() { 
     var thisZ = $(this).css('z-index') 
     return thisZ != 'auto' && parseInt(thisZ) >= topZ; 
    }).each(function() { 
     $(this).css('z-index', topZ - 1); 
    }) 
} 
Cuestiones relacionadas