Get selection object and use its type and toString method - Javascript Object

Javascript examples for Object:Object Method

Description

Get selection object and use its type and toString method

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body>
       eteetetetetete //from   w w  w .j a v a2 s.c o m
      <br>
      Current selection type : 
      <span id="t"></span> 
      <br>
      Current selection length : 
      <span id="l"></span> 
      <script>
setInterval(function(){
  var s = window.getSelection();
  document.getElementById('t').innerHTML = s.type;
  document.getElementById('l').innerHTML = s.toString().length;
}, 400);

      </script>  
   </body>
</html>

Related Tutorials