Instantiating Widgets: do the elements have to exist/be in body?

Instantiating Widgets: do the elements have to exist/be in body?

When instantiating a widget do I have to 'apply' it to an element already attached to the body element? Ie, like the following...

  1. var myWidget = $('#foo').MyWidget({option1: 'foo'})
  2. // Must add the element to the body to get it to function correctly (am I correct?)
  3. myWidget.appendTo($('body'));

Or can I just instantiate one like so...

  1. var myWidget = new MyWidget({option1: 'foo'});