A little help with HTML custom components please

Using the Javascript bridge you can affect HTML elements. The anvil.js package allows you to write anything you’d write in Javascript in Python. For example, to get that HTML element by id:

heading = anvil.js.window.document.getElementById('govuk-notification-banner-title')

From there you could change the text in it using standard Javascript techniques.

Do note that if you’re developing a custom component, and there might be more than one of these components on a form, then the ids will be duplicated and you’ll need a different approach.

Beyond that, you need to define the property in the IDE for the custom component and write the Python property functions to run when the property is set or get: Anvil Docs | Custom Components

2 Likes