Source: https://nishanth-fern-test.docs-staging.pageloop.ai/web/override-text-content-with-inner-text

# Capture the Text of an Element using innerText()

#### What is innerText and textContent?

In JavaScript, `innerText` and `textContent` are two properties that are used to access and modify the text content of an element on a web page. By default, when you select an element using Whatfix, the element text is captured using textContent().

Here are some key differences between the two:

| innerText                                                                                            | textContent                                                                  |
| ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| Retrieves the visible text content of an element.                                                    | Retrieves the content of an element, including all text and nested elements. |
| Excludes text that is hidden with CSS or rendered invisible due to its parent’s visibility settings. | Ignores the style or visibility of the element.                              |
| Returns the formatted and styled text content.                                                       | Returns the raw text content as a string.                                    |

For example, consider the following code snippet:

```plaintext
<div id="test">
  Hello <span style="display:none;">world</span>!
</div>

let element = document.getElementById("example");
console.log(element.textContent); // Output: Hello world!
console.log(element.innerText); // Output: Hello !
```

In this snippet, the element with the ID test contains a hidden element with the text world. Here's how the output varies:

- element.textContent outputs “Hello world!” (including the hidden text).
- element.innerText outputs “Hello!” (excluding the hidden text).

#### Why should I override Text Content with Inner Text?

When **Override Text Content with Inner text** is enabled, instead of capturing the textContent property of selected elements, Whatfix captures the innerText property. Here’s why:

- Visibility: By using innerText, only the text content visible to the user on the screen is captured.
- Hidden Elements: Certain text elements may be hidden or styled in a way that makes them invisible to the user. Despite this, they are still captured by the textContent property. Using innerText ensures accuracy.

Use the following steps to override textContent with innerText:

1. On the Whatfix Guidance dashboard, click **Settings**. ![ia\_left\_nav\_settings](/images/b8/ia_left_nav_settings-b868cdaa.png)

2. Click **Advanced customisation**. ![ia\_settings\_advanced configuration](/images/c0/ia_settings_advanced-configuration-c0ca1bbb.png)

3. Click **Technical configuration**. ![ac\_tech config.png](/images/ec/ac_tech-config-ec92a9c5.png)

4. Click **Add preferences**. ![tech config\_add prefrences.png](/images/bf/tech-config_add-prefrences-bfdc0f70.png)

5. Click **Common Properties**. ![tech config\_common properties.png](/images/b8/tech-config_common-properties-b80e3f41.png)

6. Select the **Override text content with inner text** checkbox. ![tech config\_enable override text content .png](/images/7c/tech-config_enable-override-text-content-7c6126ff.png)

7. Click **Add**. ![tech config\_add button.png](/images/ef/tech-config_add-button-ef8393cf.png)

8. Enable the **Override text content with inner text** toggle. ![tech config\_override text content toggle.png](/images/75/tech-config_override-text-content-toggle-750053c2.png)

9. Click **Save**. ![tech config\_save.png](/images/3d/tech-config_save-3d3f631d.png)

## Related

- [Reselect Elements to manage UI changes](/web/reselecting-elements-to-manage-ui-changes)
