Dynamically add custom attribute to element

That’s what I did as a workaround, but it’s not a solution for the general case.

That’s what I’d like to do, but I couldn’t find any example of how to do it properly. Do you have any references to where that has been done?