Range: comparePoint() メソッド

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.

Range.comparePoint() メソッドは、 -101 を返します。それぞれ、 referenceNodeRange の前か、同じか、後かを返します。

参照ノードが TextCommentCDATASection型の Node の場合、 offset は参照ノードの先頭からの文字数です。他の Node 型の場合、 offset は参照ノードの先頭からの子ノードの数です。

構文

js
comparePoint(referenceNode, offset)

引数

referenceNode

Range と比較する Node です。

offset

0 以上の整数で、 referenceNode 内のオフセットを表します。

返値

Returns -1, 0, or 1.

js
range = document.createRange();
range.selectNode(document.getElementsByTagName("div").item(0));
returnValue = range.comparePoint(document.getElementsByTagName("p").item(0), 1);

仕様書

Specification
DOM
# ref-for-dom-range-comparepoint①

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
comparePoint

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報