JavaScript Text Auto-Select onClick

If this JavaScript code example installed on a web page, when users click on text-container HTML elements then it will select all of its inner text automatically.

At present, this JavaScript code made to work on elements such as input, textarea, div, span, td, and pre. You still can edit it to work more HTML elements as you want. That's so helpful for website with a lot of text.


Sampled by © JavaScriptBank.com

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';
}

2000+ free JavaScripts
at www.JavaScriptBank.com