Opened 9 years ago
Closed 9 years ago
#10123 closed bug (notabug)
Accessing plugin instance from DOM with data() broken
Reported by: | teo8976 | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | none |
Component: | ui.widget | Version: | 1.10.4 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
According to http://learn.jquery.com/plugins/stateful-plugins-with-widget-factory/#the-widget-factory-under-the-hood
""" When a plugin instance is created, it is stored on the original DOM element using jQuery.data, with the plugin name as the key.
Because the plugin instance is directly linked to the DOM element, you can access the plugin instance directly instead of going through the exposed plugin method if you want. This will allow you to call methods directly on the plugin instance instead of passing method names as strings and will also give you direct access to the plugin's properties.
var bar = $( "<div />") .appendTo( "body" ) .progressbar() .data( "progressbar" ); // Call a method directly on the plugin instance. bar.option( "value", 50 ); // Access properties on the plugin instance. alert( bar.options.value );
"""
That doesn't work at all. $(domElement).data("pluginname") returns undefined.
Change History (3)
comment:1 Changed 9 years ago by
comment:2 Changed 9 years ago by
Ok, figured it out. The plugin's fullname is needed, i.e. prefix-fullname.
There error therefore is in the abovementioned documentation page, not a bug in the widget factory itself.
It works as expected, but the example in the documentation wouldn't (it needs to be data("ndk-progressbar")).
Apparently I can't close this report myself, so please close it, I'll report it against learn.jquery.com
comment:3 Changed 9 years ago by
Resolution: | → notabug |
---|---|
Status: | new → closed |
http://jsbin.com/xuqucare/1/edit