News Ticker

Javascript Code-Select All Text Inside Any Tag-div-p Using Javascript Code

By Ajay Verma - Wednesday 11 November 2015 No Comments
Hello friends, recently i received one comment regarding to provide a code for select all text inside any tag or div..
below is small piece of javascript you can use for this.
<html>
<head>
/**** Paste Below In Head *****/
<script type="text/javascript">
function selectText(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById
(containerid));
range.select();
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
}
} </script>
</head>
<body>
<div id="ud64_1" onclick="selectText('ud64_1')">

Your Content.... here ud64_1, is unique id replace this with
some other unique id for each div/p/tag
</div>
<p id="ud64_2" onclick="selectText('ud64_2')">
Your Content.... ud64_2, is unique id replace this with
some other unique id for each div/p/tag
</p>
<body>
</htlm>

No Comment to " Javascript Code-Select All Text Inside Any Tag-div-p Using Javascript Code "