Questions tagged [selection]

The selection can refer to text that has been highlighted, or it can refer to a choice made in UI elements that require one, e.g. a particular option in an HTML `select`. Selection is also the stage of a genetic algorithm in which individual genomes are chosen from a population for later breeding.

The selection can refer to:

  • a range of text that has been highlighted, a feature intended to mark the text for copying and, in editable areas, pasting over.

  • a choice made in UI elements that require one, e.g. a particular option in an HTML select. In UI elements, the selection is often made by means of drop-down boxes, radio buttons, checkboxes, file choosers, and more. Selections can be made with the mouse by clicking and dragging over the desired text, or by holding down the Shift key while navigating the text with the arrow keys. Selections are not usually permanent marks, and can often be removed just by clicking or selecting elsewhere.

  • the stage in genetic algorithms / programming is in which individual genomes are chosen from a population for later breeding (recombination or crossover).

4031 questions
45
votes
5 answers

Highlight text range using JavaScript

I would like to highlight (apply css to) a certain text range, denoted by its start and end position. This is more diffucult than it seems, since there may be other tags within the text, that need to be…
Vincent
  • 1,126
  • 2
  • 10
  • 11
44
votes
3 answers

selectionStart and selectionEnd in contenteditable element

I have been struggling the selectionStart and selectionEnd attributes of textarea to make them work with contenteditable div element. I have checked a lot of related articles on google and on SO but to no avail. I have something similar to the…
Semytech
  • 623
  • 1
  • 10
  • 17
44
votes
7 answers

How can I get a list of all values in select box?

I am stumped. I have a form with a dropdown list, and I would like to grab a list of all the values in the list. I pulled the below example from w3 schools (yes, I know it's unreliable, but other solutions on stack overflow seem to be very similar…
dan.m.kumar
  • 758
  • 2
  • 9
  • 20
43
votes
2 answers

How can I get the DOM element which contains the current selection?

You can select a part of a web page with the mouse. I know that I can get the currently selected text but how can I get the DOM element which contains the start or end of the current selection?
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
42
votes
9 answers

How to bind multiple selection of listview to viewmodel?

I am implementing a listview, and a button next to it. I have to be able that when i select multiple items in a listview, and then click on a button, then the selected items are put into a list. But my question is , how do i bind the selected items…
Ruben
  • 1,033
  • 3
  • 12
  • 22
40
votes
3 answers

How does one enable selections in SwiftUI's List

I am trying to create a simple multiple selection List with SwiftUI. I am unable to make it work. List takes a second argument which is a SelectionManager, so I tried creating a concrete implementation of one. But, it never gets called and the rows…
Rumbles
  • 806
  • 1
  • 8
  • 15
39
votes
3 answers

Coordinates of selected text in browser page

I need the coordinates in pixels of the beginning of the text selection (anywhere on the page, not in a textarea). I tried using the cursor coordinates but this didn't work quite well because the cursor coordinates and the beginning of the selection…
Bouke
  • 660
  • 2
  • 7
  • 22
39
votes
4 answers

window.getSelection() gives me the selected text, but I want the HTML

I'm extending a WYSIWYG HTML editor (for Firefox), I want to add tags around a selection. I can't find a function to accomplish this in the Mozilla Midas specification. There is a command to replace the selection with HTML. So if I could read the…
Bob Fanger
  • 28,949
  • 7
  • 62
  • 78
37
votes
5 answers

JavaScript: Disable text selection via doubleclick

When double-clicking on a html page most browsers select the word you double-click on (or the paragraph you triple-click on). Is there a way to get rid of this behavior? Note that I do not want to disable regular selection via single-click+dragging;…
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
37
votes
3 answers

Is it possible to select css generated content?

Let's say I have mark up:
Hello
..with CSS: div:after { content: attr(data-generated); } This produces the text: Hello world! - FIDDLE div:after { content: attr(data-generated); }
Danield
  • 121,619
  • 37
  • 226
  • 255
36
votes
3 answers

How is nth_element Implemented?

There are a lot of claims on StackOverflow and elsewhere that nth_element is O(n) and that it is typically implemented with Introselect: http://en.cppreference.com/w/cpp/algorithm/nth_element I want to know how this can be achieved. I looked at…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
34
votes
14 answers

Algorithm to find k smallest numbers in array of n items

I'm trying to write an algorithm which can print the k smallest numbers in an n-size-array in O(n) time, but I cannot reduce the time complexity to n. How can I do this?
Jessica
  • 341
  • 1
  • 3
  • 4
34
votes
6 answers

Converting Range or DocumentFragment to string

Is there a way to get the html string of a JavaScript Range Object in W3C compliant browsers? For example, let us say the user selects the following: Hello World It is possible to get "Hello World" as a string using the Range.toString()…
SamGoody
  • 13,758
  • 9
  • 81
  • 91
33
votes
6 answers

How to apply rounded borders to highlight/selection

I have used Visual Studio Online for a while for a project, and the way they apply rounded borders to selections in their online code viewer is very interesting: I've tried inspecting the element and looking for some kind of custom CSS, but had no…
Cyral
  • 13,999
  • 6
  • 50
  • 90
32
votes
5 answers

How to make element not lose focus when button is pressed?

I have a textarea in which I am inserting content at the location of the caret (thanks to Tim Down's answer). It inserts the content when the user presses a button. But it seems that when the button is pressed, the focus on the textarea is lost. How…
Lucas
  • 16,930
  • 31
  • 110
  • 182