<form name="select" class="seckod"> <script type="text/javascript"> function selectext() { document.getElementById("testarea").select() } </script> <input class="button" type="button" value="Select Codes" onClick="selectext()"> <textarea readonly="readonly" id="testarea"> <html> <head> <title></title> </head> <body> Select Me </body> </html> </textarea> </form> The codes in above works using textarea tag. How to make it to use div tag instead of textarea tag?
<html> <head> <script language="javascript"> function selectText(divid) { if (document.selection) { var div = document.body.createTextRange(); div.moveToElementText(document.getElementById("divid")); div.select(); } else { var div = document.createRange(); div.setStartBefore(document.getElementById("divid")); div.setEndAfter(document.getElementById("divid")) ; window.getSelection().addRange(div); } } </script> </head> <body> <button onclick="selectText(divid)">Select Text</button> <div id="divid">Select Me</div> </body> </html> Code (markup): it is work. the codes in above written by a sirepoint member.