3 ms·
> which to this day [the append() and prepend() functions jQuery provides] have no direct competitor in vanilla js The vanilla JS append() and prepend() method
by cantSpellSober 3y ago
> which to this day [the append() and prepend() functions jQuery provides] have no direct competitor in vanilla js
The vanilla JS append() and prepend() methods?
I understand there are differences w/these vs jQuery but, for discussion, why not use those?
https://developer.mozilla.org/en-US/docs/Web/API/Element/prepend#prepending_an_element https://developer.mozilla.org/en-US/docs/Web/API/Element/pre...
- StreamingCat 3y agoMainly 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...