Questions tagged [getselection]
198 questions
6
votes
3 answers
How to get selected text with JavaScript
I'm a little confused why doesn't this code work!
The HTML Markup:
Score some goals
The JavaScript code:
function GetSelectedText () {
if (window.getSelection) { // all browsers, except IE…
Develop Smith
- 146
- 1
- 3
- 13
5
votes
2 answers
Saving a selection for later use in JS
I've got a rich text editor in an iframe with designMode that does syntax highlighting for small blocks of text. I'd like it to update the highlighting on keyup, but messing with the DOM causes the frame to blur, thus every time you push a key the…

Monchoman45
- 517
- 1
- 7
- 17
5
votes
2 answers
Getting the next character after window.getSelection()
Is there anyway to get the next character after a window.getSelection()? I need to check if the character after the selected text is a space or not...
EDIT: Thank you for your answers! I'm basically using this link to highlight text, but would…

Eric
- 1,209
- 1
- 17
- 34
5
votes
3 answers
Can getSelection() be applied to just a certain element (not the whole document)?
I was testing out the getSelection() method, and I wanted my program to get the selected text in a certain paragraph of text and display it in a div tag. I used the following code:
var txt =…

Shrey Gupta
- 5,509
- 8
- 45
- 71
4
votes
1 answer
Value of window.getSelection() changes during callback
I am trying to store the value of window.getSelection(), but this value seems to change if the user selects another selection.
In my code below, I have stored the initial user's selection. I then create my form (which takes a bit of time), and when…

Jon
- 8,205
- 25
- 87
- 146
4
votes
3 answers
How to find the selection text beginning and end positions in Javascript?
I am trying to find the textual start and end of the selection. So, in the following text, if I selected "world! What a fine" from within "Hello, world! What a fine day it is!", I should get 7 as the start coordinate, and 24 as the end coordinate…

Tyler
- 19,113
- 19
- 94
- 151
4
votes
1 answer
getSelection() to get data from row in Google Chart API
I'm trying to trigger the creation of a new BarChart with Google's Chart API when a user clicks on a particular bar. I think I understand the concepts, and wanted to at least get the getSelection() function to work and display what bar the user…

Graham Hukill
- 61
- 1
- 1
- 3
4
votes
1 answer
How to use javascript touch events to select text on touchscreen
I have this javascript with jQuery to do the job on computer-screens with mouse and keyboard connected:
For starting the selection of text on screen:
$("body").on("mousedown", ".myDiv", async function(e) {
//do something
});
When…

Villads Claes
- 111
- 10
4
votes
2 answers
how to clone window.getSelection() object?
I'm trying to insert image to editable div. First time is working fine but after user change album (by choose select option) it doesnt work anymore.
The problem is when user 'click' select option it is change (window.getSelection()). I'm solving…

pors
- 191
- 2
- 3
- 15
4
votes
2 answers
Google Chart getSelection doesn't have column property
When I use:
chart.getChart().getSelection()[0]
on a chart (from a chartwrapper, hence the getChart() first), the getSelection() function returns
only a row-property but no column property even though my 'chart' is a table and clicking anywhere…

Sleenee
- 594
- 1
- 8
- 21
3
votes
1 answer
Javascript touchend event will not fire on Android
I'm trying to use the touchend (or the taphold event, both wont fire) as specified by jquery mobile. I'm developping an app for android using the phonegap platform. My AVD runs Android 4.0.3, and my phonegap version is 1.3.0.
As im using phonegap,…

Julz
- 157
- 1
- 3
- 9
3
votes
1 answer
how to call function after text is selected
I want to call function after text is selected in the document. Following code is not working
var showSelWin = document.getElementById('innerwindow');
var txt = ' ';
if (document.getSelection) function(){
txt =…
user1193970
3
votes
0 answers
Preserving caret position when switching from markdown to editor in vanilla JS
I am basically trying to replicate the functionality of Roam Research. The setup is:
Some text in markdown format. For example:
const markdownText = "Use **asterisks** for bold text. Use _underscores_ for italics text.";
A container div (C).
A…

Kirsdarkenvaar
- 95
- 4
3
votes
2 answers
getSelection without alt attribute and scripts in it?
I'm using window.getSelection () to get the selected text.
But, if i select an image too, it returns also altof an image.
EXAMPLE:
My text here ...
if i select an image too, it returns
image_alt My text…


Simon
- 22,637
- 36
- 92
- 121
3
votes
1 answer
react-native get selection text start and end from text component
I used Text component reference:
https://facebook.github.io/react-native/docs/text.html
with property selectable={true}, is there any solution to get the user text selection start and end on Text component not TextInput component?
because I need…

NaDa Bayomy
- 31
- 3