Which approach to displaying popups with jQuery is better?
1) To have a popup element ready () and hidden (display:none), and then displayed with it’s content procedurally generated (and hidden again after the user clicked something); or
2) To procedurally generate the and its content when it’s needed and remove it (via $(this).remove()) after the user clicks something?
Thanks!
It really depends on the usage. If it’s something that you’ll use over and over, it’s more efficient to create and show/hide the element, and store the reference to it as a single jQuery object that you only create once.
If the popup is not used as often, or its uses are particularly varied, or if state management might get overly complicated, then creating and destroying probably makes more sense.