4 ms·
That was simplified code to create just one element and add it to the DOM. Once you write it not once, but twice, or five times, you will either switch to a li
by dmitriid 7y ago
That was simplified code to create just one element and add it to the DOM.
Once you write it not once, but twice, or five times, you will either switch to a lib/framework, or to jQuery, or will write your own wrapper not that different from jQuery.
- 52-6F-62 7y agoNot for something so simple. It's trivial to abstract small, oft-repeated actions like that to their own function. As I do, regularly. And then I can give it a readable name, like `createElement` or `insertElement` with an interface like: insertElement(type: string, text?: string. attributes?: object, parent?: string): void; I prefer writing something like that with some minor case-handling over pulling in a library every time I meet a repeatable fragment. If I know I'm going to run into a large host of needs, then it's a different story. But most of the time I find jQuery overkill and somewhat opaque.
- raydev 7y agoThe reusable functions you need from jQuery likely don't justify jQuery's size. It's better to write or copy/paste wrappers for everything you need.