Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check a DOM element is inside a range

How can I check that the node from the DOM tree is inside a specific range (https://developer.mozilla.org/en-US/docs/Web/API/Range)? Of course, the node can be totally inside the range and partly inside range.

like image 917
Simon Avatar asked Feb 09 '23 11:02

Simon


1 Answers

Example

range = document.createRange();
range.selectNode(document.getElementsByTagName("div").item(0));
bool = range.isPointInRange(document.getElementsByTagName("p").item(0),1);

https://developer.mozilla.org/en-US/docs/Web/API/Range/isPointInRange

like image 70
connexo Avatar answered Feb 12 '23 01:02

connexo