JQuery · Startups

Which is the correct or better way to create a new element with jQuery?

Satvinder Singh Web and Graphic Designer at Designer ios

October 3rd, 2016

I consider myself a rookie when it comes down to programming. Thanks a lot for the thoughtful responses in advance.

geilt Insurtech. Programmer, Entrepreneur. Academic, Philosopher. Gamer, VR/AR, IoT, Biohacker.

October 4th, 2016

I prefer var element = $('<element>'). It will create the element then you can just 

$('otherselector').append(element); You can also run anything you want on element before appending or prepending or whatever. Don't forget there are many different DOM insertion functions and you will have to choose where to insert!

Tom DiClemente Management Consulting | Interim CEO/COO | Coach

October 4th, 2016

Go to https://learn.jquery.com/using-jquery-core/manipulating-elements/ and scroll down to creating new elements.