Select all contents of textbox when it receives focus (Vanilla JS or jQuery)

Jon Erickson picture Jon Erickson · Jan 26, 2009 · Viewed 302.7k times · Source

What is a Vanilla JS or jQuery solution that will select all of the contents of a textbox when the textbox receives focus?

Answer

John Sheehan picture John Sheehan · Jan 26, 2009
$(document).ready(function() {
    $("input:text").focus(function() { $(this).select(); } );
});