# get id of current cell to tell custom visualization where to plot

**URL:** <https://talk.observablehq.com/t/get-id-of-current-cell-to-tell-custom-visualization-where-to-plot/1927>\
**Category:** Help\
**Created:** [April 27, 2019, 2:41am UTC](https://talk.observablehq.com/t/get-id-of-current-cell-to-tell-custom-visualization-where-to-plot/1927 "2019-04-27T02:41:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cornhundred](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/cornhundred/32/1705_2.png) [@cornhundred](https://talk.observablehq.com/u/cornhundred)\
**Post date:** [April 27, 2019, 2:41am UTC](https://talk.observablehq.com/t/get-id-of-current-cell-to-tell-custom-visualization-where-to-plot/1927/1 "2019-04-27T02:41:13Z")

</div>

Is there a way to get the id of the current cell (e.g. r#) so that I can tell my custom visualization library ([https://github.com/ismms-himc/clustergrammer-gl](https://github.com/ismms-himc/clustergrammer-gl)) where to insert the visualization into the HTML DOM?

You can see the problem here [https://observablehq.com/@cornhundred/clustergrammer-test](https://observablehq.com/@cornhundred/clustergrammer-test)

I did not pass in an CSS id and it defaulted to full screen.

---

<div class="post-metadata">

**Author:** ![bgchen](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bgchen/32/784_2.png) [@bgchen](https://talk.observablehq.com/u/bgchen)\
**Post date:** [April 27, 2019, 3:29am UTC](https://talk.observablehq.com/t/get-id-of-current-cell-to-tell-custom-visualization-where-to-plot/1927/2 "2019-04-27T03:29:44Z")

</div>

It’s possible to get the `r#` ID by creating an HTML element in a cell and then querying for its parent ID (see e.g. [this notebook](https://observablehq.com/d/8d72f1a5131e5033)), but this is kind of a hack so I wouldn’t rely on it. I think it would be more reliable to define a named cell as in this fork:

> **[Clustergrammer Test](https://observablehq.com/d/2a04d40689b9dd45)**
>
> An Observable notebook by Bryan Gin-ge Chen.

There I used the fact that you can pass a reference to an HTML element as `args.container`. I also added some code to clean up the `something` div so that rerunning `cgm(args)` won’t keep appending more copies of the graphic to that cell.

---

<div class="post-metadata">

**Author:** ![cornhundred](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/cornhundred/32/1705_2.png) [@cornhundred](https://talk.observablehq.com/u/cornhundred)\
**Post date:** [April 28, 2019, 5:58pm UTC](https://talk.observablehq.com/t/get-id-of-current-cell-to-tell-custom-visualization-where-to-plot/1927/3 "2019-04-28T17:58:23Z")

</div>

Thanks for the help. I merged in some changes from Tom MacWright ([https://observablehq.com/@cornhundred/clustergrammer-test](https://observablehq.com/@cornhundred/clustergrammer-test)), but I need to spend some time comparing solutions.
