Thursday, July 4, 2024
HomeLanguagesJavascriptHTML DOM Range endOffset property

HTML DOM Range endOffset property

The endOffset property returns a number representing an Offset index where the Range ends. 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 index of ending character of the Range. For other Node types, the endOffset is the index of child nodes at the ending of the parent node.

Syntax:

end = range.endOffset;

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

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

Here the range’s endOffset index is 4th node from endContainer node.

HTML




<html>
<head>
<title>HTML DOM range endOffset property</title>   
</head>
<body>
    <h1>neveropen</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.endContainer);
    index=range.endOffset;
    console.log(index);
</script>
</html>


Output: In console, the endOffset 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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Ted Musemwa
As a software developer I’m interested in the intersection of computational thinking and design thinking when solving human problems. As a professional I am guided by the principles of experiential learning; experience, reflect, conceptualise and experiment.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments