Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8233299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:04:57+00:00 2026-06-07T18:04:57+00:00

I am looking for a way to select the text inside a span using

  • 0

I am looking for a way to select the text inside a span using jquery when the text is clicked on.

For example in the html snippet below, I want the text “\apples\oranges\pears” to become selected when it is clicked on.

<p>Fruit <span class="unc_path">\\apples\oranges\pears</span></p>

I’ve tried implementing this myself to no avail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:04:58+00:00Added an answer on June 7, 2026 at 6:04 pm

    A working demonstration : http://jsfiddle.net/dystroy/V97DJ/

    $('.unc_path').click(function (){
        var text = $(this).text();
        var $input = $('<input type=text>');
        $input.prop('value', text);
        $input.insertAfter($(this));
        $input.focus();
        $input.select();
        $(this).hide();
    });​
    

    The idea (see comment above) is to dynamically replace the span with an input, only cross-browser way I know to have selected text.

    Note that this is only half the road, as you probably want to deselect, style to remove border, etc.

    And I must also precise that an input, contrary to a span, cannot span on multiple lines.

    I don’t think this could/should be used in a real application except in a very specific point.


    EDIT : new version : http://jsfiddle.net/dystroy/A5ZEZ/

    In this version the text comes back to normal when focus is lost.

    $('.unc_path').click(function (){
        var text = $(this).text();
        var $this = $(this);
        var $input = $('<input type=text>');
        $input.prop('value', text);
        $input.insertAfter($(this));
        $input.focus();
        $input.select();
        $this.hide();
        $input.focusout(function(){
            $this.show();
            $input.remove();
        });
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using SQL Server 2008 R2 we are looking for a way to select the
I am looking for a more jquery/cleaner way to be able to select all
I'm looking for a way to programatically select all the content inside a TinyMCE
I am looking for a way to select text on a website in Chrome
I am looking for a way to select multiple items within a JList by
I'm looking for the best way to select numbers directly from an in clause.
I am looking for a way for users to select one of the two
I'm looking for way to write Javascript programs / scripts on desktop, not inside
I am using codeigniter and looking a way to enable directly editting of doc
I am looking for a way to change the option value from a select

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.