0

Highlight word onclick using javascript not working in ipad version 9.3.3 and iphone 6. Anyone knows the solution for ios devices. My code is given below.

<div class="collected-item">Text</div>
<div class="collected-item">Text1</div>

$(document).on('click', '.collected-item' , function(event){
      event.preventDefault();
      self._selectElementText($(this)[0]);
});

**_selectElementText**: function(el) {
    if (document.selection) document.selection.empty(); 
        else if (window.getSelection) window.getSelection().removeAllRanges();
    if (document.selection) {
        var range = document.body.createTextRange();
        range.moveToElementText(el);
        range.select();
    }
    else if (window.getSelection) {
        var range = document.createRange();
        range.selectNode(el);
        window.getSelection().addRange(range);
    }
}

It is working in android devices only problem is for ios devices.

Abhijit
  • 105
  • 2
  • 14
  • might be a duplicate of http://stackoverflow.com/questions/10577906/how-to-make-my-click-function-work-with-ios Try the css pointer option or use touch events. – Shilly Aug 25 '16 at 11:28
  • Click event is working correct. My problem is word is not selecting. I have also check with touch event but not working. Also the css option that you suggest Shilly is not working for me. – Abhijit Aug 25 '16 at 11:47

0 Answers0