Please use document.querySelector() instead. It stops after the first match, and therefore is faster in cases where there is at least one matching element.