# How to get absolute position of any node?

**URL:** https://discuss.prosemirror.net/t/how-to-get-absolute-position-of-any-node/4313
**Category:** Uncategorized
**Created:** [December 30, 2021, 10:48pm UTC](https://discuss.prosemirror.net/t/how-to-get-absolute-position-of-any-node/4313 "2021-12-30T22:48:55Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![jeremy](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/jeremy/32/2554_2.png) [@jeremy](https://discuss.prosemirror.net/u/jeremy)
#### Post date: [December 30, 2021, 10:48pm UTC](https://discuss.prosemirror.net/t/how-to-get-absolute-position-of-any-node/4313/1 "2021-12-30T22:48:55Z")

</div>

Hello, I’m trying to get the absolute positions of table cells in a table so I can change their attributes. I need to do this without selecting the table cells. For example, if someone clicks a table, and then clicks a style button, all the table cells in the table will have their attributes changed. The table is a node, the table rows are nodes, and the table cells are nodes. I’m not in any node view. So, how could I get the absolute position of a node? Thanks.

---

<div class="post-metadata">

### Author: ![bhl](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/bhl/32/4074_2.png) [@bhl](https://discuss.prosemirror.net/u/bhl)
#### Post date: [December 31, 2021, 2:29am UTC](https://discuss.prosemirror.net/t/how-to-get-absolute-position-of-any-node/4313/2 "2021-12-31T02:29:25Z")

</div>

[https://prosemirror.net/docs/ref/#view.EditorView.posAtDOM](https://prosemirror.net/docs/ref/#view.EditorView.posAtDOM)[https://prosemirror.net/docs/ref/#view.EditorView.posAtCoords](https://prosemirror.net/docs/ref/#view.EditorView.posAtCoords)

Resolve those positions with the current editorview document.

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)
#### Post date: [December 31, 2021, 11:24am UTC](https://discuss.prosemirror.net/t/how-to-get-absolute-position-of-any-node/4313/3 "2021-12-31T11:24:43Z")

</div>

You generally should track the node by position from the start. There’s not really any other way to refer to nodes—node objects’ identities aren’t useful in ProseMirror, since they have value semantics and might occur multiple times in a document, and will be copied whenever anything inside them changes.

---

<div class="post-metadata">

### Author: ![jeremy](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/jeremy/32/2554_2.png) [@jeremy](https://discuss.prosemirror.net/u/jeremy)
#### Post date: [January 2, 2022, 5:10am UTC](https://discuss.prosemirror.net/t/how-to-get-absolute-position-of-any-node/4313/4 "2022-01-02T05:10:19Z")

</div>

Thank you. I’ll take a look at that.

---

<div class="post-metadata">

### Author: ![jeremy](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/jeremy/32/2554_2.png) [@jeremy](https://discuss.prosemirror.net/u/jeremy)
#### Post date: [January 3, 2022, 11:22pm UTC](https://discuss.prosemirror.net/t/how-to-get-absolute-position-of-any-node/4313/5 "2022-01-03T23:22:43Z")

</div>

Thank you for replying. Hmm, how would I do that? Wouldn’t the node position change as text or any content is added above the table? When I select a node, and I `console.log(editor.state.selection)` I see a `path` attribute in the `selection` object. This `path` attribute is an array that seems to trace the path from the `doc` node to the selected node. How is the path calculated? Thanks

---

<div class="post-metadata">

### Author: ![jeremy](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/jeremy/32/2554_2.png) [@jeremy](https://discuss.prosemirror.net/u/jeremy)
#### Post date: [January 3, 2022, 11:44pm UTC](https://discuss.prosemirror.net/t/how-to-get-absolute-position-of-any-node/4313/6 "2022-01-03T23:44:24Z")

</div>

Another question is how can I select all the nodes of a table with just code? That might help me too. Thanks

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)
#### Post date: [January 4, 2022, 6:49am UTC](https://discuss.prosemirror.net/t/how-to-get-absolute-position-of-any-node/4313/7 "2022-01-04T06:49:41Z")

</div>

> [@jeremy](#):
>
> Wouldn’t the node position change as text or any content is added above the table?

Yes, you will have to [map](https://prosemirror.net/docs/ref/#transform.Position_Mapping) the position as transactions come in.

> [@jeremy](#):
>
> Another question is how can I select all the nodes of a table with just code?

Create a selection object (if you’re using prosemirror-tables, you probably want a `CellSelection`, otherwise this sounds like it should be a `NodeSelection`) and dispatch a transaction that sets that selection.

---

<div class="post-metadata">

### Author: ![jeremy](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/jeremy/32/2554_2.png) [@jeremy](https://discuss.prosemirror.net/u/jeremy)
#### Post date: [January 4, 2022, 3:17pm UTC](https://discuss.prosemirror.net/t/how-to-get-absolute-position-of-any-node/4313/8 "2022-01-04T15:17:50Z")

</div>

Thank you so much!
