What is the most efficient way to create HTML elements using jQuery?

Recently I’ve been doing a lot of modal window pop-ups and what not, for which I used jQuery. The method that I used to create the new elements on the page has overwhelmingly been along the lines of:

$("<div></div>");

However, I’m getting the feeling that this isn’t the best or the most efficient method of doing this. What is the best way to create elements in jQuery from a performance perspective?

This answer has the benchmarks to the suggestions below.

12 Answers
12

Leave a Comment