I'm writing a jQuery plugin that starts off like this:
$.fn.kewTip = (function() {
var $kewtip = $('<div></div>').css({'position':'absolute','zIndex':2147483647}).attr({'class':'kewtip'}).hide().appendTo('body');
You will notice that it immediately appends an element to the page body, but it can't do that until the DOM is ready, which means the plugin can't be defined until the DOM is ready either.
However, I'd ideally like calls to $('xxx').kewTip()
to not fail if they try calling it outside of $(document).ready({ ... })
. So how do I get around this?
My plugin depends on this element existing, so how do I define it before the DOM is ready?