safari-innerhtml.txt
doStuff = function() {
setInnerHTML($('#mynode'), "foo bar", function() {
// rest of doStuff() here...
});
};
setInnerHTML = function(_node, _html, _cb) {
// need to localize variables so they are available inside setTimeout below
var $node = _node;
var html = _html;
var cb = _cb;
$node.html(html);
setTimeout(function() { $node.html() == html ? cb() : setInnerHTML($node, html, cb) }, 50);
};
// or...
(function($) {
var _htmlCallback = function(_self, _html, _cb) {
var self = _self;
var html = _html;
var cb = _cb;
setTimeout(function() { self.html() == html ? cb() : _htmlCallback(self, html, cb) }, 50);
};
/*
* $(selector).htmlWithCallback("<foo>bar</foo>", function() {});
*/
$.fn.htmlWithCallback = function(html, cb) {
var self = this;
self.html(html);
_htmlCallback(self, html, cb);
};
}, jQuery);