Auto-Select | JavaScriptSource

Auto-Select

Matt Murphy Mar 7, 2008

General

This function, when called on a particular HTML element, will auto-select all of its inner text. It works on elements such as input, textarea, div, span, td, and pre.

Just click in one of the areas below for a demonstration.


A div Element:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam ultrices vestibulum elit. Mauris congue sapien sed dolor. Pellentesque sem augue, porttitor id, placerat ac, congue ac, eros. Etiam fermentum consectetuer pede. Donec tincidunt. Suspendisse non nisi. In hac habitasse platea dictumst. In hac habitasse platea dictumst. Integer porta egestas sapien.

An input Element:

A textarea Element:

A pre Element:

function toggle_visibility(id) {
  var e = document.getElementById(id);
  if(e.style.display == 'none')
    e.style.display = 'block';
  else
    e.style.display = 'none';
}

Notes

Source Code

Paste this source code into the designated areas.

External file

Paste this code into an external JavaScript file named: autoSelect.js


Head

Paste this code into the HEAD section of your HTML document.


Body

Paste this code into the BODY section of your HTML document


Leave a Response

(0 comments)