javascript - Select all DIV text with single mouse click -


How to highlight / select the contents of the DIV tag when clicking on the user div ... The idea is that all the text Highlight / selection is made, so the user does not need to manually highlight the text with the mouse and possibly miss a bit of the text

For example, we have a DIV Found:

  & lt; Div id = "selectable" & gt; Http: //example.com/page.htm< / Div & gt;  

... and when the user clicks on that URL, the entire URL text is highlighted so that they can easily drag selected text into the browser, or copy the entire URL together. Click OK.

Thank you!

  script type = "text / javascript" & gt; Function selectText (containerid) {if (document.selection) {var category = document.body.createTextRange (); Range.moveToElementText (document.getElementById (containerid)); Range.select (); } And if (window selection) {var range = document.createRange (); Range.selectNode (document.getElementById (containerid)); Window.getSelection () removeAllRanges () .; . Window.getSelection () AddRange (range); }} & Lt; / Script & gt; & Lt; Div id = "selectable" onclick = "selecttext ('selectable')" & gt; Http: //example.com/page.htm< / Div & gt;  

Now you have to pass the ID as an argument, which is "selectable" in this case, but it is more global, allowing it to be used multiple times without using it By giving, as mentioned by Chibor, JQuery


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -