Created
January 30, 2014 23:25
-
-
Save steveosoule/8722326 to your computer and use it in GitHub Desktop.
Select HTML Text With JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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