You are on page 1of 3

Web Developer Blog: jQuery Quick Tip: Select text on focus http://webdevel.blogspot.com/2008/02/jquery-quick-tip-select...

BUSCAR BLOG MARCAR BLOG Siguiente blog»Crear un blog | Acceder

Web Developer Blog


Code (C#, JavaScript, CSS, SQL etc) and useful web related utilities (freeware or open
source) as well as general coding tips.

Wednesday, February 27, 2008


jQuery Quick Tip: Select text on focus
Just a quick tip on how to select all text when focus is given
to a textarea or input (only if the value has not changed) .

Show code in new window


$("input, textarea").focus(
function()
{
// only select if the text has not changed
if(this.value == this.defaultValue)
{
this.select();
}
}
)

Posted by Sam at 2:45 PM

Labels: jQuery, tip

4 comments:

tantos said...
Thx for this tip.
My problem solved, hehe :D
8:00 AM, September 18, 2008

Jethro Larson said...


Thanks. I didn't even know the defaultValue property
existed.
7:22 PM, December 10, 2008

Text to speech said...


Thanks, your post helped me to solve this problem in about
20 seconds.
1:44 PM, March 06, 2009

Eduard Seifert said...


Quick and simple, thanks. Maybe it would be better if you
directly select the spec. input field using the jQuery css
1 de 3 selectors for attr. like this: $('input[name=name- 21/4/09 20:55
of-inputfield]').focus(...));
2:35 PM, March 21, 2009
Web Developer Blog: jQuery Quick Tip: Select text on focus http://webdevel.blogspot.com/2008/02/jquery-quick-tip-select...

This work is licenced


under a Creative
Commons Licence.

Blog Archive

▼ 2009 (10)
▼ April (4)
Chinook: Cross-
Database (SQL
Server, Oracle,
MySQL...

Code Generation
with MyGeneration

GIMP Button
Templates - Web
2.0 Style

Raphaël - a
JavaScript library
for creating
vector...

► March (1)

► January (5)

► 2008 (36)

► 2007 (37)

► 2006 (79)

► 2005 (134)

► 2004 (116)

► 2003 (30)

Labels

acrobat (1)

adobe reader (1)

ajax (1)

api (1)

array (1)

ASP.NET (11)
2 de 3 21/4/09 20:55
associative array (1)

autocomplete (1)
Web Developer Blog: jQuery Quick Tip: Select text on focus http://webdevel.blogspot.com/2008/02/jquery-quick-tip-select...

3 de 3 21/4/09 20:55

You might also like