~/Ali GÖREN

Creating HTML Element in VanillaJS

Ali Goren · · 1 dk okuma


I’ve been working on a project for a while. I don’t use jQuery. Sometimes I need to create an HTML element. For example backend data coming as JSON data.

If I use jQuery, it should be like that;

$(“

”).appendTo(“#someDiv”)
Yes, looks great. But If you’re not using jQuery, I have a small function for you.

This is an example of how can you use this function.

There is also a more optimized version of this code. Meghan mentioned it.

I use them so often I made my own library (gi... - DEV

The optimized code on GitHub

nektro/basalt

CodePen to Example

I hope this will help you.

Thanks for reading.