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.