Sunday, October 12, 2025
Latest:
  • German Pronouns with Nominative, Accusative, and Dative cases
  • German articles for the nominative, accusative, and dative cases
  • Der kleine Vogel und die Sonne
  • German alphabet pronunciation
  • Command design pattern
Upokary

Upokary

Quality information

  • Health
  • Life
  • Fashion
  • Food
  • Code
  • English
  • বাংলা
Technology 

How to get the selected text from a HTML document using JavaScript?

Published: February 22, 2020Last updated: July 22, 2020 JavaScript

The use case was quite simple. We had an HTML document where the user was selecting a block of text. We wanted to get that selected text using JavaScript. Following the code segment that does that in JavaScript:

window.getSelection().toString

Source:
Selected text JavaScript

Get selection JavaScript

You May Also Like

How to add multiple language support in ReactJS with i18next and react-i18next?

September 30, 2020 beroza

Parsing error: Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment

August 23, 2019 beroza

Reasons of timeout when trying to connect EC2 instance.

January 13, 2020 beroza

How to generate a unique random ID using JavaScript?

October 31, 2019 beroza

Write a Program to Count Largest Group

January 6, 2023 beroza

Write a Program to Find Number of Senior Citizens

May 28, 2023 beroza

Positions of Large Groups

December 27, 2022 beroza

Find if the sum of two integers is equal to the given value

February 10, 2022 beroza

Iframe lazy loading

January 5, 2021 beroza

Why Upokary?

Upokary.com is a useful application in everyday life. It provides very handy information regarding every aspect of life. Each and every tip of upokary.com is meant to make life better.

Upokary tools

  • Youtube thumbnail
  • Youtube video downloader

Useful Links

  • Handy code
  • Technology
  • People
  • Programming
  • Quote
  • Travel
  • WordPress
  • IELTS
  • Kids

Pages

  • Sitemap
  • Privacy policy
  • About us
  • Contact us

Support

For any kind of query or question please drop a message in the following email: upokary@gmail.com
Copyright © 2025 Upokary. All rights reserved.