Skip to content

Instantly share code, notes, and snippets.

@steveosoule
Created January 30, 2014 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveosoule/8722326 to your computer and use it in GitHub Desktop.
Save steveosoule/8722326 to your computer and use it in GitHub Desktop.
Select HTML Text With JavaScript
<!-- FROM: http://us5.campaign-archive1.com/?u=ea228d7061e8bbfa8639666ad&id=c53c1e7832&e=ff0570c0b6 -->
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<input value="Web Tools Weekly" id="textField">
<button id="btn">Select Text</button>
<script>
var tf = document.getElementById('textField'),
btn = document.getElementById('btn');
btn.onclick = function () {
// change the numbers to select a different range
tf.focus();
tf.setSelectionRange(5, 9);
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment