Код: Выделить всё
const target = window.getSelection()?.focusNode;
Код: Выделить всё
console.log((target as HTMLElement));
console.log((target as HTMLElement).parentNode as HTMLElement);
((target as HTMLElement).parentNode as HTMLElement)?.append(
rows
);
((target as HTMLElement).parentNode as HTMLElement)?.append(
''
);
(((target as HTMLElement).parentNode as HTMLElement)?.childNodes[
((target as HTMLElement).parentNode as HTMLElement)?.childNodes.length - 1
] as HTMLElement).innerHTML = '';
Код: Выделить всё
((target as HTMLElement).parentNode as HTMLElement) returns null
Код: Выделить всё
let counter = 0;
const tt = setInterval(() => {
const
t1 = (target as HTMLElement),
t2 = ((target as HTMLElement).parentNode as HTMLElement)
;
if(t1 !== null && t2 !== null) {
((target as HTMLElement).parentNode as HTMLElement)?.append(
rows
);
((target as HTMLElement).parentNode as HTMLElement)?.append(
''
);
(((target as HTMLElement).parentNode as HTMLElement)?.childNodes[
((target as HTMLElement).parentNode as HTMLElement)?.childNodes.length - 1
] as HTMLElement).innerHTML = '';
clearInterval(tt);
}
else {
if(counter > 30) {
clearInterval(tt);
}
}
counter++;
}, 1);
Подробнее здесь: https://stackoverflow.com/questions/793 ... eturn-null
Мобильная версия