Reputation: 887
I have a page that has a lot of JS created elements. So i wish to focus a textarea after it appear. I try to make it with help of addEventListener
like so:
mytextarea.addEventListener('someEvent', function(e)
{
this.focus();
});
My problem is, that i can not found the right Event, that would be fired at the moment, when textarea get appended in the document, like here
document.getElementsByTagName('body')[0].appendChild(mytextarea);
Native JS Only please. Thank you
Upvotes: 0
Views: 499
Reputation: 601
Put your focus
in
$(document).ready(function(){
//Here
});
This mean your textarea
is appended to the document
.
And without jQuery :
window.addEventListener('load', function () {
//here
});
Upvotes: 0
Reputation: 73906
Have you tried this:
document.getElementsByTagName('body')[0].appendChild(mytextarea);
mytextarea.focus();
Upvotes: 1