Reputation: 10781
How can I target the second to last child in this example?
if( ($(this).is(":last-child")) || ($(this).is(":eq(-2)")) ) {
:last-child
works for me but not :eq(-2)
.
Upvotes: 0
Views: 7327
Reputation: 876
I have try this code is working fine.
Example:
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);
}
Upvotes: 0
Reputation: 16777
Try using the :nth-last-child() selector.
if ($(this).is(":last-child, :nth-last-child(2)"))
Description: Selects all elements that are the nth-child of their parent, counting from the last element to the first.
jQuery( ":nth-last-child(index/even/odd/equation)" )
index: The index of each child to match, starting with the last one (1), the string even or odd, or an equation ( eg. :nth-last-child(even), :nth-last-child(4n) )
Version added: 1.9
Upvotes: 5