Sometimes, we want to select all div text with single mouse click with JavaScript.
In this article, we’ll look at how to select all div text with single mouse click with JavaScript.
How to select all div text with single mouse click with JavaScript?
To select all div text with single mouse click with JavaScript, we can use the window.getSelection
and selectAllChildren
methods.
For instance, we write
window.getSelection().selectAllChildren(document.getElementById(id));
to call getElementById
to get an element with the given id
.
Then we call getSelection
to return an object with the selectAllChildren
method to get all child nodes from the element with the given id
.
Conclusion
To select all div text with single mouse click with JavaScript, we can use the window.getSelection
and selectAllChildren
methods.