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 1068797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:19:57+00:00 2026-05-16T20:19:57+00:00

Is it possible to retrive selected text outside textbox? I had seen solutions to

  • 0

Is it possible to retrive selected text outside textbox?
I had seen solutions to get text from input forms and textareas, similar to this:
http://laboratorium.0xab.cd/jquery/fieldselection/0.2.3-test/test.html
but can this aplied on HTML text (inside div element)?

For example, I want user to be able to bold selected text which is not in textarea.

  • 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-05-16T20:19:58+00:00Added an answer on May 16, 2026 at 8:19 pm

    Yes, it’s possible. IE and other browsers have rather different mechanisms for dealing with selections. If you simply want the selected text, the following will do it:

    function getSelectedText() {
        var text = "";
        if (window.getSelection) {
            text = "" + window.getSelection();
        } else if (document.selection && document.selection.createRange &&
                document.selection.type == "Text") {
            text = document.selection.createRange().text;
        }
        return text;
    }
    

    To address your specific question, you can use document.execCommand("bold", null, false); to make the current selection bold. In non-IE browsers you have to temporarily put the document into edit mode first though:

    function toggleSelectionBold() {
        var range, sel;
        if (window.getSelection) {
            // Non-IE case
            sel = window.getSelection();
            if (sel.getRangeAt) {
                range = sel.getRangeAt(0);
            }
            document.designMode = "on";
            if (range) {
                sel.removeAllRanges();
                sel.addRange(range);
            }
            document.execCommand("bold", null, false);
            document.designMode = "off";
        } else if (document.selection && document.selection.createRange &&
                document.selection.type != "None") {
            // IE case
            range = document.selection.createRange();
            range.execCommand("bold", null, false);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to retrieve stored credentials from the browser cache if you use
Given a sessionid, is it possible to retrieve that information from wherever the session
I have a row list as [10,20,30] i want to pass the selected row
Is possible to have the posts loaded into an swf using the wordpress framework?
Is it possible to retrieve information like: the tables the indexes with the columns
I may miss the obvious, but how/is it possible to retrieve interrupt counters for
I'm working with a legacy database which due to poor management and design has
I have a BorderContainer that has an HTML element inside of it. The HTML
today i tested the geolocation system implement by google on Chrome, with this page:

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.