jquery - Can't add to DOM content before page load Javascript -
jquery - Can't add to DOM content before page load Javascript -
i trying add together bunch of elements list using javscript after querying parse.
i able total list if don't add together click listeners, if add together click listeners, first 5 items appear in list.
here code in javascript file, called first in html:
if (!parse.user.current()){ window.location.href = 'index.html'; } else { getparticipants(); } $( document ).ready(function() { $('#sign-out').click(function(){ parse.user.logout(); window.location.href = 'index.html'; });
});
function getparticipants (){ var participants = parse.object.extend("participants"); var query = new parse.query(participants); query.ascending("patientid"); query.find({ success: function(results) { (var = 0; < results.length; i++) { var object = results[i]; var id = object.get("patientid"); $(".list-group").append("<li class='list-group-item' id='" + id + "'>" + id + "</li>"); (function (id) { $('#' + object.get("patientid")).click(function (e) { e.preventdefault(); if (typeof(storage) !== "undefined") { localstorage.setitem("patientid", id); } else { // sorry! no web storage support.. } window.location = 'profile.html'; }); }(id)); } }, error: function(error) { alert("error: " + error.code + " " + error.message); } });
}
you can never modify dom before page loads because @ point dom isn't ready.
any dom manipulation should done after onload event fired.
javascript jquery parse.com
Comments
Post a Comment