As Code Duck pointed out, jQuery traverses nodes in the original order, in depth - or, as you call it, pre-order. However, contents only gets nodes for children, not descendants. Try the following:
$(document).contents ().each (function processNodes () { if (this.nodeType == 3) doSomething (this);
As a third-party, arguments.callee flagged for deprecation, therefore a named function (as opposed to anonymous)
source share