Skip to content

Instantly share code, notes, and snippets.

@jonathansampson
Created June 3, 2016 00:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathansampson/6d09bd6d2e8c22c53868aec42e66b0f9 to your computer and use it in GitHub Desktop.
Save jonathansampson/6d09bd6d2e8c22c53868aec42e66b0f9 to your computer and use it in GitHub Desktop.
A polyfill for Range.prototype.intersectsNode
if ( !Range.prototype.intersectsNode ) {
Range.prototype.intersectsNode = function ( node ) {
let range = document.createRange();
range.selectNode( node );
return 0 > this.compareBoundaryPoints( Range.END_TO_START, range )
&& 0 < this.compareBoundaryPoints( Range.START_TO_END, range );
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment