These two blocks of code has subtle difference which is very important.
//adds element to DOM and *then* does the manipulation $('&lt;div /&gt;').appendTo(someElement).doSomeManipulation(); //manipulates the element fragment *before* adding to the DOM $('&lt;div /&gt;').doSomeManipulation().appendTo(someElement);
It’s very important to know when elements have been added to the DOM, but be aware of manipulating them once they are being placed.
Sam Deering has 15+ years of programming and website development experience. He was a website consultant at Console, ABC News, Flight Centre, Sapient Nitro, and the QLD Government and runs a tech blog with over 1 million views per month. Currently, Sam is the Founder of Crypto News, Australia.