ExpertRefresh

Uncategorized / Textarea get selected text  


Document ready
<script> $(document).ready(function(){ $('textarea#content').select(function(){ var selectedText = window.getSelection().toString(); alert(selectedText); }); }); </script>
onClick
<script> function highlightText() { var selectedText = window.getSelection().toString(); var highlightText = selectedText.replace(selectedText, "xxx" + selectedText + "xxx"); var contentText = $('textarea#content').val(); contentText = contentText.replace(selectedText, highlightText); $('textarea#content').val(contentText); } </script>


References



n/a