Suppose I have a simple HTML page with a textarea
, and I want to wrap that textarea
in a DIV. However, this doesn't always happen on startup / page load, so the user might have focus in that area, or even be typing.
I can move / wrap the area by creating a DIV, appending it to the textarea
's parent, then putting the textarea
inside of it, and it works great. However, when I do that, focus is removed from the textarea
and if the user was in the middle of typing, they're going to get angry.
How can I move the textarea
's DOM node without interrupting the user? Is this even possible?
Depending on the browser you may be able to determine which element has focus by using document.activeElement. Save the value before performing the move and then afterwards set the focus back using .focus() in the textarea is the same element as what you saved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With