jQuery append not completing before next statement?
<p>I have a survey-type form that's being populated from a web database on the client.  I can populate the questions fine, but then I try to go through and trigger the click event where there is an existing answer (edit scenario), I'm finding that the new elements are not yet in the DOM so this doesn't work.  Here's the code:</p>

<pre><code>$(function() {
    var db = openDatabase(...);
    db.transaction(function(tx) {
        tx.executeSql("select ....", [surveyId], function(tx, results) {
            var items = "", answers = [];
            for (var i = 0; i &lt; results.rows.length; i++) {
               var id = results.rows.item(i).id;
               items += "&lt;div&gt;&lt;input type='radio' name='q-" + id + "' id='q-" + id + "-1' /&gt;&lt;label for='q-"+id+"-1'&gt;Yes&lt;/label&gt;&lt;input type='radio' name='q-" + id + "' id='q-" + id + "-2' /&gt;&lt;label for='q-"+id+"-2'&gt;No&lt;/label&gt;&lt;/div&gt;";
               if (result.rows.item(i).answer) {
                   answers.push('#q-'+id+'-'+results.rows.item(i).answer);
               }
            }
            $('#questions-div').append(items);
            $.each(answers, function(i, e) { $(e).click(); });
        });
    });
});
</code></pre>

<p>Any tips how I can make this work, or better generally?</p>
