2012-04-13 16 views
10

たとえば、z-index = 10でHTML要素(-s)を見つける方法はありますか?指定されたZ-インデックスを持つ要素を検索

+0

可能重複[jQueryの:あなたは、CSSルールではなく、クラスによって選択することができますか?](http://stackoverflow.com/questions/43926/jquery-can-you- CSSでルールを選択しないでください) –

+0

:[jQueryがインラインCSS属性で検索する](http://stackoverflow.com/questions/1180067/jquery-find-by-inline-css-attribute) – aruseni

+1

ドン't。このアプローチを使用している場合、おそらく何か間違っているでしょう。代わりにidsやクラスを使用してください。 – Blazemonger

答えて

17

あなたはすべての要素を反復処理し、そのZインデックスをチェックする必要があります。

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

一つの可能​​性[jQueryの]解決策:

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

ただ、CSSへのマッチを探し要素をループルール。

1

あなたはすべての要素を取得し、CSSのプロパティでそれらをフィルタリングすることができます:クローム43で私のテストで

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

、私は100%役立つことが@ThiefMaster's postを見つけましたが、ありません。引っ張られるz-indexの値は文字列でした。

これは可視要素に対してのみ反復処理を行い、autoを処理しました。

ここに私の更新です:の

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); 
    }) 
} 
関連する問題