# d3: how to select a node by text content?

**URL:** <https://talk.observablehq.com/t/d3-how-to-select-a-node-by-text-content/9710>\
**Category:** Help\
**Created:** [August 28, 2024, 2:09pm UTC](https://talk.observablehq.com/t/d3-how-to-select-a-node-by-text-content/9710 "2024-08-28T14:09:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stuvjordan-uroc](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/stuvjordan-uroc/32/6808_2.png) [@stuvjordan-uroc](https://talk.observablehq.com/u/stuvjordan-uroc)\
**Post date:** [August 28, 2024, 2:09pm UTC](https://talk.observablehq.com/t/d3-how-to-select-a-node-by-text-content/9710/1 "2024-08-28T14:09:27Z")

</div>

How do you use `d3.select` to get a node by its text content?

[This stackoverflow answer](https://stackoverflow.com/a/42500468/7071537) made me think that I could use `d3.selection.text()` as a getter, and thus filter the results of a `selectAll` by the text content of the returned nodes.

But mimicking the pattern shown in that stackoverflow answer is not working for me. Instead, I’m getting the error

```auto
TypeError: Cannot read properties of null (reading 'textContent')

```

[Here is a notebook demonstrating my failed attempt](https://observablehq.com/d/06afd6b7efc222c5).

---

<div class="post-metadata">

**Author:** ![mcmcclur](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mcmcclur/32/2364_2.png) [@mcmcclur](https://talk.observablehq.com/u/mcmcclur)\
**Post date:** [August 28, 2024, 3:19pm UTC](https://talk.observablehq.com/t/d3-how-to-select-a-node-by-text-content/9710/2 "2024-08-28T15:19:20Z")

</div>

I don’t believe that arrow functions bind `this`. Try a `function` function:

```
d3.select(test).selectAll('g.test-class > text').filter(function() {
  return d3.select(this).text() === "second node"
}).attr('fill', 'red')

```
