Should also add tabindex="0" so it can be reached by keyboard. So add icon.setAttribute('tabindex', '0');