How do I force an Id of a component?
Application Type


I implemented Google Tag Manager on my project and I need to force some id in some components so I can keep track of them.
So this is my problem. I have a WebBlock with a dropdown and I type the Id that I want on the Name property (screenshot) . When I go to the html code it appears with some random characteres (screenshot).

How do I force the Id that I want?

Thank you!! :)

Rank: #95

Hello Daniela,

Hope you are doing well.

If you want to force the Id of an element, you should be able to do it using JavaScript.

For example, you can implement it like this:

document.getElementById($parameters.WidgetId).id = $parameters.NewWidgetId;

where WidgetId is an Input Parameter (text) where you should pass the original Id of the element and NewWidgetId is another Input Parameter (text) where you should pass the value that you want.

Then you just need to pass the correct values:

You should place this JavaScript in your Block's OnReady event.

Let us know if it worked for you :)

Hope that this helps!

Kind regards,

Rui Barradas