Should use the getElementsByTagName + reverse while approach to boost performance just like you did for the td elements.