Reputation: 2768
If for example I have the next event:
document.getElementById('TagSearchInput').onkeyup = function(e)
{
//Code...
}
Inside the event, there is a condition where I recreate the element (TagSearchInput
). How can I refresh the event selector, from within the event?
Upvotes: 0
Views: 357
Reputation: 150080
OK, ignoring any questions about why you'd be recreating the input...
Rather than using an anonymous function try something like this:
function TSIKeyupHandler(e)
{
//Code...
// within your condition where you want to re-attach the handler
document.getElementById('TagSearchInput').onkeyup = TSIKeyupHandler;
}
document.getElementById('TagSearchInput').onkeyup = TSIKeyupHandler;
(Optionally put all of the above inside an immediately-invoked-anonymous-function if you want to keep the TSIKeyupHandler()
function out of the global scope.)
Upvotes: 3