--- title: "Element inference: keep Userflow finding elements when class names or IDs change" slug: "element-inference-and-dynamic-class-names" description: "Optimize Userflow.js for dynamic class names and IDs to enhance element inference and ensure accurate targeting in your app. Get expert configuration help!" updated: 2026-10-26T16:17:00Z published: 2026-10-26T16:17:00Z canonical: "help.userflow.com/element-inference-and-dynamic-class-names" stale: true --- > ## Documentation Index > Fetch the complete documentation index at: https://help.userflow.com/llms.txt > Use this file to discover all available pages before exploring further. # Element inference: keep Userflow finding elements when class names or IDs change Element inference is how Userflow.js remembers an element you selected in your app, such as the target of a tooltip or a launcher, so it can find the same element again later. If your app's class names or IDs change every time you deploy, Userflow.js can lose track of the element. Your developers can tell Userflow.js which class names and IDs to ignore, using the code on this page. ## What is element inference in Userflow? Element inference is the process Userflow.js uses to recognize an element you selected in your app. When you select an element, Userflow.js records information about it, such as its class names, its ID and other attributes, and uses that information to find the same element on later page loads. If those class names or IDs are generated by your app and change with each deploy, the recorded information no longer matches, and Userflow may show an [Element not found](https://help.userflow.com/docs/element-not-found) message. A tooltip that worked before and stopped after a new release of your app is a common sign. Before changing code, you can often fix a single element in the flow builder: adjust strictness, or use **Go manual** with a stable attribute such as `data-testid`. See [Selecting elements](https://help.userflow.com/docs/tooltip-element-selection). The settings on this page fix the problem for every element in your app at once. Each element inference setting goes in your app's code, before the line that calls `userflow.init()`. ## How do I make Userflow.js ignore dynamic class names? Use `userflow.setInferenceClassNameFilter` to tell Userflow.js which class names to ignore. For example, a CSS-in-JS library might generate class names in the format `css-<hash>`, where `<hash>` changes with every deploy. Add this line before you call `userflow.init()`: ```plaintext userflow.setInferenceClassNameFilter(cls => !cls.startsWith('css-')) ``` You can also use a negative lookahead regular expression that only matches class names that don't start with `css-`: ```plaintext userflow.setInferenceClassNameFilter(/^(?!css-).*/) ``` To filter by more than one pattern, or to use functions instead of regular expressions, see [userflow.setInferenceClassNameFilter in the Userflow.js reference](https://docs.userflow.com/docs/userflow-js#setinferenceclassnamefilter). If all of your app's class names are dynamic, you can tell Userflow.js to ignore every class name with a filter that always returns false: ```plaintext userflow.setInferenceClassNameFilter(() => false) ``` Only do this if none of your class names are stable. Ignoring useful, non-dynamic class names makes it harder for Userflow to find elements. ## How do I make Userflow.js ignore dynamic IDs? By default, Userflow.js uses an element's `id` attribute, unless the ID ends in a number. Userflow.js skips those IDs so that it works out of the box with frameworks such as Ember.js, which give elements IDs like `ember123`. If your app generates IDs in a different pattern, use `userflow.setInferenceAttributeFilter`. Add this line before you call `userflow.init()`: ```plaintext userflow.setInferenceAttributeFilter('id', id => !id.startsWith('auto-')) ``` This example tells Userflow.js to ignore all IDs that start with `auto-`. For details, see [userflow.setInferenceAttributeFilter in the Userflow.js reference](https://docs.userflow.com/docs/userflow-js#setinferenceattributefilter). ## Which element attributes does Userflow.js use, and how do I change them? By default, Userflow.js may use the values of these element attributes to recognize an element: - `data-for` - `data-id` - `data-testid` - `data-test-id` - `for` - `id` - `name` - `placeholder` - `role` To use a different set of attributes, call `userflow.setInferenceAttributeNames` with the list you want. Add this line before you call `userflow.init()`: ```plaintext userflow.setInferenceAttributeNames(['name', 'placeholder', 'data-testid']) ``` For details, see [userflow.setInferenceAttributeNames in the Userflow.js reference](https://docs.userflow.com/docs/userflow-js#setinferenceattributenames). If you'd like help configuring element inference for your app, [contact us](https://userflow.com/contact). ## Related articles - [Selecting elements](https://help.userflow.com/docs/tooltip-element-selection) - [Element not found](https://help.userflow.com/docs/element-not-found) - [Userflow.js Installation](https://help.userflow.com/docs/userflowjs-installation)