DEV Community

Discussion on: Beyond appendChild: Better convenience methods for HTML

Collapse
 
samthor profile image
Sam Thorogood

I nearly didn't include this one—it was added last. But I've seen a few people remark on how neat it is in some of my codebases, so I'm glad to share? 🤷

Collapse
 
maxart2501 profile image
Massimo Artizzu

It's so useful when adding a bunch of properties to .style 🙂

Object.assign(el.style, {
 left: x + 'px',
 top: y + 'px'
});
Thread Thread
 
nickytonline profile image
Nick Taylor • Edited

I made a little helper function based on your example @samthor which also handles inline styles. Thought I'd share here in case anyone else finds it useful. So the only thing else I added was handling inline style and wrapped it all into a function.