Simple jQuery and CSS code snippets to highlight text on page in order to select it for copy or it could be used in combination with a search script to show where matches are found on a page.

Note: CSS3-only feature (only Firefox and Safari too as far as I know).

::selection {
    background: #ffb7b7; /* Safari */
::-moz-selection {
    background: #ffb7b7; /* Firefox */

Or use a textbox:

function selectAllText(textbox) {
jQuery('#txtInput').click(function() { selectAllText(jQuery(this)) });
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

Free Guide:

How to Choose the Right Charting Library for Your Application

How do you make sure that the charting library you choose has everything you need? Sign up to receive this detailed guide from FusionCharts, which explores all the factors you need to consider before making the decision.

  • Jerry

    Your online demos seem to be pointing to that json tree viewer – past couple of times…

    • jquery4u

      Hi Jerry, good spot! My bad, i’ll update the right demo link.

Learn JavaScript for free!
Free course: Introduction to JavaScript

Yours when you take up a free 14-day SitePoint Premium trial.