<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WebView-swift.class/setSelectedDOMRange(_:affinity:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(cs)WebView(im)setSelectedDOMRange:affinity:"
  },
  "title" : "setSelectedDOMRange(_:affinity:)"
}
-->

# setSelectedDOMRange(_:affinity:)

Selects a range of nodes.

```
func setSelectedDOMRange(_ range: DOMRange!, affinity selectionAffinity: NSSelectionAffinity)
```

## Parameters

`range`

The range of nodes to select. If `range` is `nil`, the current selection is cleared. This method raises a `DOMRangeExcepton` if the range has been detached or refers to nodes not displayed by the receiver.

`selectionAffinity`

See the [`selectionAffinity`](/documentation/WebKit/WebView-swift.class/selectionAffinity) property for information on selection affinity.

## See Also

[`func editableDOMRange(for: NSPoint) -> DOMRange!`](/documentation/WebKit/WebView-swift.class/editableDOMRange(for:))

Returns the editable DOM object located at a given point.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)