2 ms·
Mainly because the vanilla append/prepend functions require that you create an element first, then insert it at the desired position. The ease of use of jQuerys
by StreamingCat 3y ago
Mainly because the vanilla append/prepend functions require that you create an element first, then insert it at the desired position. The ease of use of jQuerys string to html node isnt matched by vanilla js in these functions.
The closest you would get is this:
https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML https://developer.mozilla.org/en-US/docs/Web/API/Element/ins...
But the jQuery prepend/append functions are still easier to read and shorter to write.
- cantSpellSober 3y agoFair arguments; the selector engine is flexible and terse. $.html() was great but I prefer createElement() because it guarantees I'm working with valid HTML, vs $.html("my typo here"). Interesting the article uses innerHtml in its helper function, jQuery's .html() method itself includes the comment "See if we can take a shortcut and just use innerHTML" https://github.com/jquery/jquery/blob/4a13266efd262a92f05d86b71d715885de103e6d/src/manipulation.js#L262-L299 https://github.com/jquery/jquery/blob/4a13266efd262a92f05d86...