There is at least one way
var els = document.querySelectorAll('#divConfirm table')[1].querySelectorAll('tr');
var last = [].slice.call(els).pop();
but the next statement
But if I do not know the length before running the script
it makes no sense, you already have a collection of elements, so you always know the length
var els = document.querySelectorAll('#divConfirm table')[1].querySelectorAll('tr');
var last = els[els.length - 1];
Another variant:
document.querySelector('#divConfirm table:nth-child(2) tr:last-child');
source
share