English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
getSelection()The method returns a Selection object that represents the range of text selected by the user or the current position of the insertion point.
window.getSelection()
var selObj = window.getSelection();Test and See‹/›
The numbers in the table specify the first browser version that fully supports the getSelection() method:
Method | |||||
getSelection() | Yes | Yes | Yes | Yes | 9 |
Return Value: | Selection Object |
---|
You can use CSS to set styles for selected text:
/* Firefox syntax */ ::-moz-selection { background: cyan; {} ::selection { background: cyan; {}Test and See‹/›
CSS Referenceselection pseudo-element