Add javascript events to udelements

Hi. Is there a way to add javascript events like onclick event to html elements created via New-UDElement ?
I tried to add the onclick attribute, but it does not seems to work.

Hi @sandy37! I think this might be helpful if you’re looking to develop custom components: Building Custom Components - PowerShell Universal

That said, I think a lot of what you’re looking for does already exist in the UD Ecosystem, either as built-in tools, IMS developed, or community developed components.

Have you checked out the Marketplace?

Little known tidbit of functionality. New-UDElement will bind event handlers that you pass a script block to.

For example, this div now has an onClick event handler that will show a toast.

    New-UDElement -tag 'div' -Content {
        "Nice"
    } -Attributes @{
        onClick = {
            Show-UDToast "Hi from a div"
        }
    }

Here’s an input that will show a toast on change.

    New-UDElement -tag 'input' -Content {} -Attributes @{
        onChange = {
            Show-UDToast "Hi from an input"
        }
    }
2 Likes