Document.createRange()

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.

io error: No such file or directory (os error 2) (/home/runner/work/yari/yari/mdn/translated-content/files/zh-tw/web/api/document/index.md)

回傳一 Range 物件。

語法

range = document.createRange();

創造 rangeRange 物件.

示例

js
var range = document.createRange();

range.setStart(startNode, startOffset);
range.setEnd(endNode, endOffset);

註意

Range 被創建之後,必須先設定其範圍初始點及結束點, 才能使用大部分 Range 所提供的方法。

規範