How can I wait for nextElementSibling to exist then execute my function on on it