on-internet
← Community

Add event listener on element focus

Stack Overflow ·

I have a search box input that opens when an icon is clicked on. I would like to give the input focus when the icon is clicked and call the function addLabel() that adds a label as placeholder text until a “onkeydown” event is fired, at which time it should call the function removeLabel(). Currently, my script adds focus(), but doesn’t acknowledge the other event listeners. Any help would be appreciated! window.onload = function() { <!--create absolutly positioned label as placeholder text for search--> var el = document.getElementById('gsc-i-id1'); var label = document.createElement('label');

Comments

Sign in or sign up to comment and upvote.

No comments yet.