I need to know if the el
in a View has been attached to the DOM because I'm trying to apply a jQuery plugin, but the plugin requires the el
to be in the DOM first.
Inspired by How do I check whether a jQuery element is in the DOM? I get this to work:
render : function() {
...
if (this.$el.closest('html').length) // test if in DOM
this.$el.someJqueryPlugin();
return this;
}
I also need the owner of this view to trigger an 'onshow' right after the el is inserted to the DOM, which is doable, but kind of clumsy.
Another solution I can think of is to do this:
var el = $('<div>').appendTo(somewhereInsideDOM);
var view = new view(el:el);
In this case, the el will always be attached to the DOM and much less clumsy this way, but the downside would be manipulation of el means manipulating the DOM. Lastly, with this method, the this.className
is not respected. An additonal .addClass(this.className)
is needed.
Any other solution?