Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if jquery-mobile loaded

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

like image 966
Alex Avatar asked Dec 19 '12 18:12

Alex


2 Answers

You can check if one of the functions is there.

if ( $.mobile ) {
   //jq mobile loaded
} else {
  // not
} 
like image 172
Amir T Avatar answered Sep 21 '22 20:09

Amir T


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
});
like image 31
Gajotres Avatar answered Sep 19 '22 20:09

Gajotres