Skip to content

Commit 97807c1

Browse files
committed
Widget: Document how to retrieve a widget's instance and how to tell whether an element has a widget bound to it. Fixes #77.
1 parent 83b2f52 commit 97807c1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

entries/jQuery.widget.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@
8484
</code></pre>
8585

8686
<p>All widgets have a <code>create</code> event which is triggered upon instantiation.</p>
87+
88+
<h3>Instance</h3>
89+
90+
<p>The widget's instance is stored using jQuery core's <a href="http://api.jquery.com/jQuery.data/">data method</a> with the widget's full name as the key. Therefore, you can use the following to retrieve the progressbar widget's instance object from the element.</p>
91+
92+
<pre><code>
93+
$( "#elem" ).data( "ui-progressbar" );
94+
</code></pre>
95+
96+
<p>Whether an element has a given widget bound to it can be determined using the <a href="data-selector"><code>:data</code></a> selector.</p>
97+
98+
<pre><code>
99+
$( "#elem" ).is( ":data( 'ui-progressbar' )" ); // true
100+
$( "#elem" ).is( ":data( 'ui-draggable' )" ); //false
101+
</code></pre>
87102
</longdesc>
88103
<category slug="utilities"/>
89104
</entry>

0 commit comments

Comments
 (0)