Second last child without jquery
The text node can be a problem in both lastChild and previousSibling This worked for me:
documentObject.lastElementChild.previousElementSibling
Found the other part of the solution here: https://stackoverflow.com/a/18341945/8486854
You should be able to grab your element with
documentObject.lastChild.previousSibling
where documentObject
is your parent
.
Edit
Thank you to David Thomas: Even more accurate would be previousElementSibling
because it returns an Element and not a text node:
documentObject.lastChild.previousElementSibling
Sources:
W3Schools
developers.mozilla
If I undestood you correctly you could count from the end with :nth-last-child()
:
.outer *:nth-last-child(2){
color: green;
}