I'd recommend to create a "prototype" of the custom element in some extra structure and get it from there in the script. A simple example how to do this is in the GZIP grammar. The advantage of this approach is that you can configure the custom element including colors and description once and use it multiple times.