The Selection.rangeCount read-only property returns the number of ranges in the selection.
Selection.rangeCount
MDN Reference