Get selecte text in one paragraph : Text Selection : HTML JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » HTML » Text Selection »

 

Get selecte text in one paragraph



<html>
<head>
<script>

// global
var selectionStart;

// invoked by onselectstart
function saveStart() {
    selectionStart = event.srcElement;
}
// invoked by onmouseup
function selection2Element() {
    if (event.srcElement == selectionStart) {
        var rng = document.selection.createRange();
        var newHTML = "<span class='newSpan'>" + rng.text + "</span>";
        rng.pasteHTML(newHTML);
    else {
        alert("Please restrict selections to within a single paragraph.");
    }
}
</script>
</head>
<body>
 <p onmouseup="selection2Element()" onselectstart="saveStart()">select me</p>


</body>
</html>

           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo HTML
» Text Selection