Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <input type="text" placeholder="cursor holder" /><br>
  <input id="hw" type="text" value="hello beautiful world" /><br>
  <button id="focus">set focus</button>
</body>
</html>
 
$.fn.selectRange = function(start, end) {
    if(typeof end === 'undefined') {
        end = start;
    }
    return this.each(function() {
        if('selectionStart' in this) {
            this.selectionStart = start;
            this.selectionEnd = end;
        } else if(this.setSelectionRange) {
            this.setSelectionRange(start, end);
        } else if(this.createTextRange) {
            var range = this.createTextRange();
            range.collapse(true);
            range.moveEnd('character', end);
            range.moveStart('character', start);
            range.select();
        }
    });
};
var toggle = false;
setInterval(function() {
    if(toggle) {
        $('#hw').selectRange(6, 15);
    } else {
        $('#hw').selectRange(8);
    }
    toggle = !toggle;
}, 500);
$('#focus').on('click', function() {
  $('#hw').focus();
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
mnpennerpro
0viewers