Avoiding traversing through entire dom twice.