この例で最後から 2 番目の子をターゲットにするにはどうすればよいですか?
if( ($(this).is(":last-child")) || ($(this).is(":eq(-2)")) ) {
:last-child
私にはうまくいきますが、そうではありません:eq(-2)
。
この例で最後から 2 番目の子をターゲットにするにはどうすればよいですか?
if( ($(this).is(":last-child")) || ($(this).is(":eq(-2)")) ) {
:last-child
私にはうまくいきますが、そうではありません:eq(-2)
。
:nth-last-child() セレクターを使用してみてください。
if ($(this).is(":last-child, :nth-last-child(2)"))
説明:最後の要素から最初の要素まで数えて、親の n 番目の子であるすべての要素を選択します。
jQuery( ":nth-last-child(index/even/odd/equation)" )
index:一致する各子のインデックス。最後のもの (1) から始まり、偶数または奇数の文字列、または方程式 (例: :nth-last-child(even)、:nth-last-child(4n) )
追加されたバージョン: 1.9
これを試して:
$(this).is(":nth-last-child(2)")
このコードが正常に動作することを試しました。
例:
var abs = '<?php echo $this->getOrder()->getStatusLabel() ?>';
//alert(abs);
if(abs == "Delivery Complete"){
//alert('Sucssess')
var asscer = document.getElementsByClassName('form-buttons')[0].lastChild;
asscer.style.display = "none";
}
if(abs == "Pending with OPS"){
var asscer = document.getElementsByClassName('form-buttons')[0].lastChild.previousSibling;
asscer.style.display = "none";
//alert(asscer);
}