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?
console. log("not loaded"); If the above code writes “loaded” on console window, that means jQueryUI is loaded.
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.
“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.
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()); }
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
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