Get reference to all instances of jquery ui widget?
Posted
by
Hailwood
on Stack Overflow
See other posts from Stack Overflow
or by Hailwood
Published on 2012-11-02T22:56:58Z
Indexed on
2012/11/02
23:00 UTC
Read the original article
Hit count: 289
I am writing a jquery UI widget that simply wraps the bootstrap popover plugin, In the widget you can pass in the option 'singular', if this is passed in then it should call a function of all other instances of the plugin.
something like
$('#one').myWidget();
$('#two').myWidget();
$('#three').myWidget();
$('#four').myWidget();
$('#one').myWidget('show'); //stuff from widget one is now visible
$('#two').myWidget('show'); //stuff from widget one and two are now visible
$('#three').myWidget('show'); //stuff from widget one, two and three are now visible
$('#two').myWidget('hide'); //stuff from widget one and three are now visible
$('#four').myWidget('show', {singular:true}); //stuff from widget four is now visible
So, I imagine the show function looking like:
show: function(options){
options = options || {};
if(options.singular){
var instances = '????'; // how do I get all instances?
$.each(instances, function(i, o){
o.myWidget('hide');
});
}
this.element.popover('show');
}
So, question being, how would I get a reference to all elements that have the myWidget
widget on them?
© Stack Overflow or respective owner