Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to know if a jQuery UI Widget has been applied to a DOM object

Tags:

I'm using jQuery and have some interactions with a jQuery UI where I need to get options. However there's a possibility that the jQuery UI function has not been applied yet to the DOM object. I'm getting a JavaScript error right now when I access an option.

I have a DOM object that has the progressbar (http://docs.jquery.com/UI/Progressbar) attached to it (maybe). In another thread, I'm trying to access the options using domObj.progressbar("option", "value").

How do I determine if that domObj has a progressbar attached?

like image 366
DMCS Avatar asked Oct 01 '09 17:10

DMCS


People also ask

How do I know if jQuery UI is loaded?

console. log("not loaded"); If the above code writes “loaded” on console window, that means jQueryUI is loaded.

Is jQuery UI included in jQuery?

jQuery UI is a widget and interaction library built on top of the jQuery JavaScript Library that you can use to build highly interactive web applications.

Is jQuery UI still used?

“According to Builtwith, of the top 10,000 websites about 88% (or close to 9,000) of them are currently using jQuery as of the beginning of 2019.” jQuery is a well-tested library with a large community of developers who continue to contribute time and effort to modernize and improve the library.


2 Answers

You can access the progress bar object on the element by doing:

$("#myid").data("progressbar") 

So to use this:

var progressBar = $("#myid").data("progressbar"); if ( progressBar == null ) {     // handle case when no progressbar is setup for my selector } else {     alert("The value is: " + progressBar.value()); } 
like image 70
jamiebarrow Avatar answered Nov 19 '22 11:11

jamiebarrow


As of jQuery UI 1.11, widgets can be directly tested for via the instance method:

var hasProgressbar = ($(element).progressbar("instance") !== undefined); 

Documentation: http://api.jqueryui.com/jQuery.widget/#method-instance

like image 29
jdmichal Avatar answered Nov 19 '22 12:11

jdmichal