I am making a phonegap application with jquery. I am confused whether I should wrap my entire code inside JQuery’s $(document).ready() like
$(document).ready(function(){
//mycode
});
or inside the deviceready event of phonegap like
document.addEventListener("deviceready", function(){
//mycode
});
I am currently using document.ready but I think I may encounter problems if I try to access some Phonegap API methods inside document.ready.
Which is the best event to wrap my code in, document.ready or deviceready?
You should use the deviceready event to avoid funny things happening.
The docs state:
Typically, you will want to attach an event listener with
document.addEventListeneronce the HTML document’s DOM has loaded.Read the documentation here:http://docs.phonegap.com/en/1.0.0/phonegap_events_events.md.html