Is there anyway of detecting if the jquery-mobile/or any other library is loaded?
I know I could do a simple $('#button').button('enable');
just as mentioned here How to enable a jQuery Mobile button? but for fun I just want to know if there is any way of detecting if a library is loaded, and then execute the code above
You can check if one of the functions is there.
if ( $.mobile ) {
//jq mobile loaded
} else {
// not
}
This is how you do it with jQM:
$(document).bind("mobileinit", function(){
//apply overrides here
});
This is a moment when jQM starts to execute. It is executed only once.
You can read more about it here: http://jquerymobile.com/demos/1.0.1/docs/api/globalconfig.html
But in your case it is a bit different. You need to wait for DOM to be loaded to change something in page content, the best jQM practice for that case is a pagebeforeshow event :
$('#pageID').live('pagebeforeshow', function (event) {
// Some code here
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With