I have a javascript function to select the content of a cell (html table) onclick="select_cell(this)"
. No surprise, it works fine everywhere except IE. The weird part is that I discovered that if I set a timeout, it works... 100 ms was not enough: it was working half the time. With 200 ms, it's working great!
function select_cell(element){
if (window.getSelection) {
var range = document.createRange();
setTimeout(function(){
range.selectNode(element);
window.getSelection().addRange(range);
}, 200);
}
else if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(element);
range.select();
}
}
The thing is that I don't like this timeout. Someone has an explanation? Or even better, a solution to skip this timeout?