I'm not familiar with such attributes,
can someone provide a simple demo?
I need it to be done without any libraries.
<script type="text/javascript"> function ShowSelectionInsideTextarea() { var textComponent = document.getElementById('mytextarea'); var selectedText; // IE version if (document.selection != undefined) { textComponent.focus(); var sel = document.selection.createRange(); selectedText = sel.text; } // Mozilla version else if (textComponent.selectionStart != undefined) { var startPos = textComponent.selectionStart; var endPos = textComponent.selectionEnd; selectedText = textComponent.value.substring(startPos, endPos) } alert("You selected: " + selectedText); } </script>
2.1m questions
2.1m answers
60 comments
57.0k users