I'm executing these simple rows of javascript in latest ie 11, just to select all content of a div
Here a screenshot from ie11 dev tool
Like you can see, IE alter me saying: "unable to complete the operation due to error 800a025e".
I'm not able to understand the nature, the source, of the problem, and no others stack overflow questions I read give me a clear answer.
This is full code of my selectText jQuery "personal" extension
jQuery.fn.selectText = function(){
var doc = document;
var element = this[0];
// console.log(this, element);
if (typeof element == 'undefined') {
return;
}
if (doc.body.createTextRange) {
var range = document.body.createTextRange();
range.moveToElementText(element);
range.select();
} else if (window.getSelection) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
};
Element in this case is a
[Object HTMLTableElement]
Edit 1: with a little mod:
var range = document.body.createTextRange();
var retval = range.moveToElementText(element);
console.log (retval);
range.select();
I'm able to say you retval is undefined. This code work on ff without problems, so element selector is fine. jQuery version is 1.11
I resolved using this trick:
I wrapped the html table with a DIV
I use the same code, as is, with no changes, against the DIV, instead of using for selecting only the table.
It's working.
Probably html table is not a selectable text for IE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With