Open In App

HTML DOM Range startOffset property

Last Updated : 14 Jul, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The startOffset property returns a number representing an Offset index where the Range starts. This is a read-only property.

if the parent node of Range is a Node of type Text then the offset index will be the number of characters from the start of the Range. For other Node types, the startOffset is the number of child nodes from the start of the startContainer parent node.

Syntax:

start = range.startOffset;

Return Value: It returns a Offset index of starting of the range.

Example: In this example, we will use this property to get startOffset index.

Here the range’s startOffset index in 3rd node from startContainer node.

HTML




<html>
<head>
<title>HTML DOM range startOffset property</title>   
</head>
<body>
    <h1>GeeksforGeeks</h1>
     
 
<p>This is the Range Content</p>
 
 
</body>
<script>
    let range = document.createRange();
    let referenceNode = document.getElementsByTagName('p').item(0);
    range.selectNode(referenceNode);
    console.log(range.startContainer);
    index=range.startOffset;
    console.log(index);
</script>
</html>


Output: In console, the startOffset Index can be seen.

Supported Browsers: 

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Safari 1 and above
  • Opera 9 and above
  • Internet Explorer 9 and above

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads