Menu

gitpiper

DOM Selection Cheat Sheet in April 2024

Last Updated: 30 March 2024

README.md

{: .-three-column}

Selection

var sel = document.getSelection()

See: https://devdocs.io/dom/selection

Methods

sel.removeAllRanges() //  deselects
sel.addRange(range) //    sets a selection
sel.removeRange(range) // remove a range
sel.rangeCount
sel.getRangeAt(0) // get the 0th range

Collapsing

sel.collapse(parent, offset)
sel.collapseToEnd()
sel.collapseToStart()
sel.isCollapsed
sel.containsNode(node)

Deleting

sel.deleteFromDocument()

Events

document.addEventListener('selectionchange', () => {})

338+ more cheat sheets for you in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️