0

I'm trying to figure out why I get the following error which happens when I don't wrap the jquery tagit function in a document.ready function.

Uncaught TypeError: Object [object Object] has no method 'tagit' 

This is not required for most jQuery plugins so I'd like to modify the tagit.js file such that this doesn't happen. I can't find a difference between this and other jQuery plugins that don't require document.readyso I'm wondering if someone might take a look at it? https://github.com/aehlke/tag-it/blob/master/js/tag-it.js

(function($) { 
    $.widget('ui.tagit', {
...
    });
})(jQuery);
tim peterson
  • 23,653
  • 59
  • 177
  • 299
  • Could you please tell us what the problem is with initializing your plugin in `document.ready`'s event handler? – Sk8erPeter Aug 08 '13 at 17:41
  • @Sk8erPeter there is no problem. I just want to understand why this plugin has this requirement. – tim peterson Aug 08 '13 at 17:46
  • You said you want to modify this, but it doesn't make sense. With `.ready()` event handlers you can execute functions immediately after the DOM is fully loaded (_ready_). It seems like you just need to understand why using `.ready()` event handler is needed, so the question's title is a bit misleading. Read these: http://stackoverflow.com/questions/2809530/under-what-circumstances-is-jquerys-document-ready-not-required, http://stackoverflow.com/questions/3528198/jquery-is-document-ready-necessary, http://stackoverflow.com/q/5468982/517705, http://stackoverflow.com/q/6005789/517705, etc. – Sk8erPeter Aug 08 '13 at 19:04
  • @Sk8erPeter I understand the `doc.ready` function in general. What Im interested in is understanding what piece of code in **this particular plugin** makes the doc.ready function necessary. – tim peterson Aug 08 '13 at 19:17
  • When you use this plugin, you modify the "behavior" of an `` element (for the tagging opportunity). It means when you execute your JavaScript code, this element has to be already loaded/rendered by the browser. The `.ready()` event handler ensures that the DOM is ready, so no such problems can occur that the element can not be modified yet. You can also put the JS-code in the ` – Sk8erPeter Aug 09 '13 at 22:07

0 Answers0