HTML DOM Range collapse() Method
The collapse() method collapses the Range to one of its boundary points.
A collapsed Range is an empty range and doesn’t contain any content.
Parameters: This method takes boolean value as parameter.
- true: Collapses the Range to its start.
- false: Collapses the Range to its end.
Return value: This method has no return value.
Example: This example shows how to collapse a range using this method. Collapsed property is used to check if the range is collapsed or not.
Output: In console, we can see that the range is collapsed using this method.
Before Clicking the Button:
After Clicking the Button:
Supported Browsers: The browsers supported by DOM Range collapse() method are listed below:
- Google Chrome
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML course.