Re-use result instead of querying the DOM for selector multiple times

It's a complicated query, we should not repeat it when not necessary.

Change-Id: I71d47de088afa7dab0a6eaed214c61db699fcd0c