|
|
Here’s a simple script that highlights the Text in a TextBox using jQuery, when the user clicks inside it. This technique of highlighting text is useful in forms when there are frequent copy paste operations.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Click and Highlight Text</title>
<script src="http://code.jquery.com/jquery-latest.js"
type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#Text1").click(function() {
$(this).focus();
$(this).select();
});
});
</script>
</head>
<body>
<input id="Text1" type="text" value="There is some text here"/>
</body>
</html>
Here’s a Live Demo
'Like' us on our FaceBook page if you find this blog useful. Thanks!
Did you like this post?
|
|
|
||
|
|
|
|
Save on Delicious |
|
|
subscribe via rss |
|
subscribe via e-mail |
|
|
print this post |
|
follow me on twitter |





comments
1 Response to "Click and Highlight Text in a TextBox using jQuery"One of jQuery's cool features is nested function-calls. The code could be written as follows instead:
$(this).focus().select();
This avoids calling the jQuery-function (or $) twice as well as saving some bytes.
Post a Comment