0

I have a textarea with class 'test', and a 'click' event to set selection range(using setselectionRange()).In IE, After adding 'setSelectionRange' method in 'click' event, highlighting text on double click is broken. Please find the code below:

$(document).ready(function(){
 $(".test").click(function(event){
     event.target.setSelectionRange(event.target.selectionStart, event.target.selectionEnd);
});
});

Can someone suggest a workaround for this issue?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Olive
  • 21
  • 3
  • https://stackoverflow.com/questions/1981088/set-textarea-selection-in-internet-explorer && supported for IE9+ https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange – clucle Feb 14 '19 at 08:41
  • Can you provide a complete example to test please? – Silvio Biasiol Feb 14 '19 at 08:44
  • I created a textarea field with a class 'test' and added a click event to set selectionrange. This breaks highlight on double click – Olive Feb 14 '19 at 10:09
  • I find that your code is not selecting the range when you click on textarea. This thing maybe affecting the double click of textarea in IE and text not get selected when you double click. If you remove that setSelectionRange code than you will find that it is working properly. So I suggest you to try to fix your code will also fix the issue for IE. – Deepak-MSFT Feb 15 '19 at 03:21
  • I have to set focus manually on click, to fix a focus issue in my application. So i should have that code and make double click work. I tried using $(event.target).focus(). still the double click highlight functionality is broken – Olive Feb 15 '19 at 08:13
  • Your description is little confusing. I try to test with that event and find that When I double click on text area than also click event execute first. If your goal is to select the text when you click on textarea than you can check code in this link. https://textuploader.com/155ec Other than that you can try to use CreateTextRange(). var range = e.createTextRange(); range.collapse(true); range.moveEnd('character', end); range.moveStart('character', start); range.select(); Ref: https://gist.github.com/beiyuu/2029907 – Deepak-MSFT Feb 18 '19 at 08:53
  • 'select()' selects the entire text in textarea. i don't want that functionality. There is a default functionality, which selects the word on double click. This default behaviour is broken after setting the focus manually to textarea using $(event.target).blur().focus() on click. – Olive Feb 18 '19 at 09:14
  • The thing I don't understand, why do you need to set focus to textarea while clicking on it. it will get focus by itself. do you have any issues with that? I suggest you to post a clear code which can help to produce the issue. currently you are saying that focus() on click has issue, in the original post there is a code to select the range which is confusing me about the issue. If possible for you than try to provide a detailed description about overall issue, I will again try to make a test with it to provide further suggestions. Thanks for your understanding. – Deepak-MSFT Feb 21 '19 at 07:28

0 Answers0