Create element that disallows children

I’m adding an <img> element to the DOM so want to set the property children: false when creating the element how do I go about this?

Video showing the issue: Loom | Free Screen & Video Recording Software | Loom

You don’t need to set any property. The image element cannot have children, you simply add the element to the DOM, e.g.

var img = document.createElement('img');
img.src = 'https://whatever/product.jpg';
document.body.appendChild(img);

This is what I have already, but it creates an element with the property children:true which allows elements to be created within it, and when you do it crashes Webflow.

hi @dmatthams

As @memetican mentioned when dynamically creating <img/> there is no children property. Can you post screenshot or short video about your issue and read-only to your project to see what is in your code?

Here’s a video showing the issue: Loom | Free Screen & Video Recording Software | Loom

A log of the created object:

And link to the docs showing what the children property does: DOMElements

Ok you are talking about new WF API 2 plugins . Sorry I have never use it so I can’t help. But still is valid that image can’t have children that is why is crashing. IMO this should be dynamically changed by API based on element type. :person_shrugging:

https://www.w3.org/TR/2011/WD-html5-author-20110809/the-img-element.html

https://www.w3.org/MarkUp/html3/img.html

Yes ideally it would create an actual Webflow Image element, it’s early days though :wink:

You can change prototype property value or remove it with JS but…

1 Like

I tried this, and it works client-side – but as soon as you refresh it reverts back to children:true

Thanks of the suggestions though!

Yeh, like I said before this should be handled by API it self to prevent crashing when trying add children to element that is not allowed to have it. :upside_down_face: