Event handler in HTML not working in both desktop mode and mobile mode

I want to trigger an click event in HTML component, afte I write the code in it, it doesn’t work.

2 Likes

Hi @Salesbay_Australia,

As you mentioned, the Click event is not working in the HTML/CSS component because this component does not support scripting; it only supports HTML and CSS.

I believe the Event Handlers section should be removed or disabled for this component by Retool Team (@Jen , @Darren , @Jack_T , @ChiEn), as it can create confusion for users who expect the click event to work.

Hopefully, this clarifies the behavior.

1 Like

Hello there @Salesbay_Australia and @WidleStudioLLP,

@WidleStudioLLP you're right that the HTML component doesn't support scripting, so inline JavaScript like onclick= or a <script> tag won't run. That's why nothing happened when the code was added.

But the Click event handler isn't broken, and it doesn't need to be removed. It just works a little differently. Instead of scripting, you make an element clickable by adding a data-click-target attribute to it:

<div data-click-target="submit">Click me</div>

Then add a Click event handler on the HTML component (in the Interaction section of the inspector), and use target.type to tell which element was clicked:

if (target.type === "submit") {
  // run your query, open a modal, etc.
}

This is documented here: HTML component docs.

On the mobile side, I've gone ahead and enabled the feature flag for your org, so clickable HTML is now turned on for you there. :partying_face:

Can you please confirm if the mobile side is working now?

If you've set it up this way on desktop and it's still not firing, could you share a screenshot of your event handlers plus the HTML in the component's value? Happy to take a closer look. :folded_hands:

1 Like