Tuesday, November 19, 2024
Google search engine
HomeLanguagesJavascriptHTML DOM Range setEndAfter() Method

HTML DOM Range setEndAfter() Method

The Range setEndAfter() method is used to set the end position of a Range relative to another Node. An element used to set the ending point range is referenceNode element. In this method, the reference element is used and its content is included in the range.

Syntax:

range.setEndAfter( refNode );

Parameters:

  • refNode: The Node that sets the ending of the range.

Return Value: This method does not return any value.

Example: This example describes how to set the ending position of the range. Also in this example, we have used setStartBefore() method to set the starting of the range. The end reference node is the second <i> element of the document.

HTML




<!DOCTYPE html>
<html>
 
<body>
    <h1>neveropen</h1>
 
    The range will start from 1st
    element in italics <i> RangeStart</i>
    and end at 2nd italics element
    <i>RangeEnd</i>
 
    <script>
        var range = document.createRange();
        var startNode = document
            .getElementsByTagName("i").item(0);
 
        var endNode = document
            .getElementsByTagName("i").item(1);
 
        range.setStartBefore(startNode);
        range.setEndAfter(endNode);
        console.log(range);
    </script>
</body>
 
</html>


Output: In console, the created range can be seen.

Supported Browsers:

  • Google Chrome 1
  • Edge 12
  • Firefox 1
  • Safari 1
  • Opera 9
  • Internet Explorer 9
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!

RELATED ARTICLES

Most Popular

Recent Comments