Is there any alternative to document.getSelection().addRange()
?
In a content editable frame containing div
s, it gets slower as we go down the div
s.
Is there any alternative to document.getSelection().addRange()
?
In a content editable frame containing div
s, it gets slower as we go down the div
s.
Are you running removeAllRanges
first? The MDN article and this SO answer make it seem like that call is required / recommended.
An example script from the MDN article:
/* Select all STRONG elements in an HTML document */
var strongs = document.getElementsByTagName("strong");
var s = window.getSelection();
if(s.rangeCount > 0) s.removeAllRanges();
for(var i = 0; i < strongs.length; i++) {
var range = document.createRange();
range.selectNode(strongs[i]);
s.addRange(range);
}