Set tag name dynamically

Hi,

is it possible to set the tag name dynamically (by conditions) via bindings or something?

image

Best regards

Hi @Detzler, Yes, it’s possible. You can use custom code. For Example:- document.getElementById("idName").setAttribute("", "")

Hi @garima , do you mean plain DOM manipulation after React rendering?
I thought about an easier solution via the Builderio UI and maybe a line of JS script in the binding section.

@Detzler Here yo go: Loom | Free Screen & Video Recording Software | Loom

Hi @garima
it’s impressive that you take the time for creating a loom video. I appreciate that.

Don’t misunderstand me, It’s not about the attributes. I know how to add them conditionally. “Element data binding” works very well for that.
Instead, I want to set the TAG / Element Name dynamically:

image

My use case is: When a component receives a data property (Link) then the element should be an Anchor otherwise it should stay a div.

@Detzler For your use case, unfortunately, this cannot be directly available as a feature but it works in the same way as suggested in Loom. You need to add Custom Javascript in Data Tab>Edit Content JS which checks if any tag has an attribute link( if (element.hasAttribute("link")) ) then the tag should replace with an anchor tag.

@garima That’s what I thought. Thank you for your effort.
Could you pass it as a feature request?

Another often use case is:
When adding headlines to content, sometimes one want to have a h1 or just a simple div. The tag name is dependent of the criteria which the SEO-experts dictate. In this case I would create a symbol which takes two properties (text for the headline and tagName). This would allow me to use one symbol for any headlines in any contexts.

@Detzler For sure, encourage you to submit a feature request here ideas.builder.io