Search and Top Navigation
#10123 closed bug (notabug)
Opened June 22, 2014 06:41PM UTC
Closed June 23, 2014 12:34PM UTC
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.
Attachments (0)
Change History (3)
Changed June 22, 2014 06:43PM UTC by comment:1
Changed June 22, 2014 06:50PM UTC by comment:2
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
Changed June 23, 2014 12:34PM UTC by comment:3
resolution: | → notabug |
---|---|
status: | new → closed |
http://jsbin.com/xuqucare/1/edit