Get selected elememnt : Text Selection : HTML JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » HTML » Text Selection »

 

Get selected elememnt



<html>
<head>
<script>
function selection2Element() {
    var rng = document.selection.createRange();
    var newHTML = "<span class='newSpan'>" + rng.text + "</span>";
    rng.pasteHTML(newHTML);
}
</script>
</head>
<body>
<p onmouseup="selection2Element()">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