The HTML DOM Range setStartAfter() method sets the starting position of a Range. An element used to set the starting point range is referenceNode element. In this method, the reference element used is not included in the range.
Syntax:
range.setStartAfter(refNode);
Parameters:
- referenceNode element: The Node which is used to set the starting of the range.
Return Value: This method has no return value.
Example: This example will show how to set the starting of the range using setStartAfter(). Also in this example, I had also used setEndAfter() method to set the ending of the range. The start reference node here is the first <i> element of the document.
For reference, i had also console logged the range in the text to make it clear.
<html> <head> <title>HTML DOM range setStartAfter() property</title> </head> <body> <h1>GeeksforGeeks</h1> The range will start after 1st element in italics<i> RangeStart </i> The range started after 1st i element <i>RangeEnd</i> </body> <script> var range = document.createRange(); var refNode1 = document.getElementsByTagName("i").item(0); var refNode2 = document.getElementsByTagName("i").item(1); range.setStartAfter(refNode1); range.setEndAfter(refNode2); console.log(range); console.log(range.toString()) </script> </html> |
Output: In console, range made with startOffset and endOffset can be seen.
Supported Browsers:
- Google Chrome
- Edge
- Firefox
- Safari
- Opera
Recommended Posts:
- HTML | DOM HTML Object
- HTML | DOM isEqualNode() Method
- HTML | DOM History go() Method
- HTML | DOM Input Date stepUp() Method
- HTML | DOM console.warn() Method
- HTML | DOM console.clear() Method
- HTML | DOM blur() Method
- HTML | DOM createElement() Method
- HTML DOM queueMicrotask() Method
- HTML | DOM Location replace() Method
- HTML | DOM close() Method
- HTML | DOM createAttribute() Method
- HTML | DOM writeln() Method
- HTML | DOM console.trace() Method
- HTML | DOM createComment() Method
- HTML | DOM console.table() Method
- HTML | DOM console.time() Method
- HTML | DOM createTextNode() Method
- HTML | DOM console.error() Method
- HTML | DOM console.count() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


